问题
I want to rename a file in Java. My working platform is Ubuntu. The renameFile()
didn't work for me. Is there any other ways to rename a file ?
ADDED :
File file = new File( "/home/test/filename.txt" );
if ( file.renameTo( new File( "/home/test/modified.txt" ) ) ) {
System.out.println( "Rename succesful" );
} else {
System.out.println( "Rename failed" );
}
回答1:
You can use File.renameTo(newFileName)
If this doesn't work, you need to work out why as this method isn't very helpful. e.g. you can't rename a files which isn't there or you don't have permissions to the directories.
来源:https://stackoverflow.com/questions/18721750/how-to-rename-file-in-java-ubuntu-platform