Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Atomic Rename using Files.move

924454Mar 16 2012 — edited Mar 16 2012
Hi,

I want to rename file atomically:

Path source = Paths.get(pathOfFile);
Path dest = Paths.get(pathOfFile + ".txt");
Files.move(source, dest, StandardCopyOption.ATOMIC_MOVE);

It is documented that "AtomicMoveNotSupportedException" is thrown if the move cannot be performed as an atomic file system operation.

Is it dependent on the operating system to throw this exception or not (e.g. in Windows it is always thrown, but in linux based systems it is never thrown).

Or it may be thrown in both of the operating systems only in some special cases (e.g. when the target location is on a different FileStore and would require that the file be copied, or target location is associated with a different provider to this object. - javadoc of the method)

If i always use valid relative path names, then may i be sure that i will never get this exception in both linux and windows based operating systems when renaming?

Thanks

Erdem
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 13 2012
Added on Mar 16 2012
1 comment
767 views