Atomic Rename using Files.move
924454Mar 16 2012 — edited Mar 16 2012Hi,
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