Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between File.renameTo and Files.move: Which is faster?

Tags:

java

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?

like image 710
Jam Hong Avatar asked Mar 21 '12 07:03

Jam Hong


1 Answers

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

like image 192
Chandra Sekhar Avatar answered Nov 03 '22 14:11

Chandra Sekhar