Tuesday, March 1, 2011

How to rename a file in Java

try {
    File fileBeforeRename = new File("c:\\a.txt");
    File fileAfterRename = new File("c:\\b.txt");
    boolean result = fileBeforeRename.renameTo(fileAfterRename);
    System.out.println(result);
} catch (Exception e) {
    e.printStackTrace();
}

No comments:

Post a Comment