Can we rename a file say test.txt
to test1.txt
?
If test1.txt
exists will it rename ?
How do I rename it to the alrea
Try This
File file=new File("Your File");
boolean renameResult = file.renameTo(new File("New Name"));
// todo: check renameResult
Note : We should always check the renameTo return value to make sure rename file is successful because it’s platform dependent(different Operating system, different file system) and it doesn’t throw IO exception if rename fails.