Reputation: 129
Both File.renameTo
and Files.move
in Java can move a file. What's the difference between the two? And which has a better performance?
Upvotes: 12
Views: 10777
Reputation: 19492
public boolean renameTo(File dest)
Renames the file denoted by this abstract pathname.
Many aspects of the behavior of this method are inherently platform-dependent: The rename operation might not be able to move a file from one file system to another and it might not succeed if a file with the destination abstract pathname already exists.
But the move
method can move or rename a file in a platform independent manner.
renameTo
is just returning a boolean type but the move
returns the path to the target file
Upvotes: 10