Tuesday, August 31, 2010

Article | Java Program for Moving a file from current directory

Java Program for Moving a file from current directory.



  1. import java.io.*;

  2. class Abcd

  3. {

  4. public static void main(String args[])

  5. {

  6. try{BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

  7. String sr=System.getProperty("user.dir");

  8. File file = new File(sr+\\invent.dat);
  9. // Destination directory

  10. File dir = new File("E:\\java");

  11. // Move file to new directory

  12. boolean success = file.renameTo(new File(dir, file.getName()));

  13. if (!success) { System.out.print("\n Error");//File Not FOund or any other error

  14. }

  15. System.out.print("\n Directory is "+sr);

  16. br.readLine();}catch(Exception e){}

  17. }

  18. }

Loading...

Comments :

0 comments to “ Java Program for Moving a file from current directory ”

Top Views

BloggerTipsTemplates

CHICKLETS

Enter your email address:

Delivered by FeedBurner

Followers