Jam Hong
Jam Hong

Reputation: 129

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

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

Answers (1)

Chandra Sekhar
Chandra Sekhar

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.

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

Upvotes: 10

Related Questions