Reputation: 10703
I encounter a strange problem while coding. I have to rename file named börsenzeitung_komplett
to processed_börsenzeitung_komplett
.
I am using currentFile.renameTo(newFile)
from Java API, which is working fine on Windows system but returning false on GNU/Linux system.
Upvotes: 1
Views: 1588
Reputation: 18214
You should check the privileges of the output directory (and optionaly change it using chmod) or if the destination file already exist (I assume that you're not using any SecurityManager
).
As java.util.File Javadoc says:
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 filesystem to another, it might not be atomic, and it might not succeed if a file with the destination abstract pathname already exists. The return value should always be checked to make sure that the rename operation was successful.
Note that the Files class defines the move method to move or rename a file in a platform independent manner.
Upvotes: 1