To rename a file or folder in Java you can use the following snippet.

Sample Java

File source = new File("oldDirectoryOrFilePath");  
File target = new File("newDirectoryOrFilePath"); 
boolean done = source.renameTo(target);  
if (!done) {  
    // renaming failed  
}  

2 thought on “How to rename a file or folder in Java”

Leave a Reply