Pages

Friday, June 10, 2011

Java -=- Renaming a file

To rename a file, simply do the following:


// File (or directory) with old name
File file = new File("oldname");

// File (or directory) with new name
File file2 = new File("newname");

// Rename file (or directory)
boolean success = file.renameTo(file2);
if (!success) {
    // File was not successfully renamed
}

No comments:

Post a Comment