Monday, February 28, 2011

How to rename a file in Java

This simple example shows you how to rename a file in Java.
try {
    File oldFile = new File("C:\\a.txt");
    File newFile = new File(C:\\b.txt);
    boolean isSuccess = oldFile.renameTo(newFile);
    System.out.println(isSuccess);
} catch (Exception e) {
    e.printStackTrace();
}

No comments:

Post a Comment