Moving a File or Directory to Another Directory

// File (or directory) to be moved File file = new File("filename"); // Destination directory File dir = new File("directoryname"); // Move file to new directory boolean success = file.renameTo(new File(dir, file.getName())); if (!success) { // File was not successfully moved }

Comments

17 Feb 2010 - 4:30am by Mythili (not verified)

How to move selected pictures from one folder to another using Java

9 Jul 2010 - 9:45pm by rams (not verified)

its very useful to me

9 Jul 2010 - 9:48pm by rams (not verified)

how to move file using sockets

8 Aug 2010 - 10:34pm by imal hasaranaga (not verified)

i tryied that code and it worked when i try to move a file to D:/abc but when i try to move a file to C:/windows/asd the code doesnt work????? how can i move a file to C directory windows folder?????

19 Aug 2010 - 7:29pm by alex (not verified)

does this apply both for windows and for ubuntu -linux? I need a code that will work for both OS in one program.. thanks in advance.

Post a comment

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image. Ignore spaces and be careful about upper and lower case.