Pages

Friday, June 10, 2011

Java -=- Moving a file

To move a file from a directory to another, simply do the following:


// 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
}

No comments:

Post a Comment