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?
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.
Source
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With