public class FileMovingUtil extends Object
java.io.File.renameTo(java.io.File) doesn't work across NFS file
systems.
This code is taken from a workaround provided on the Sun Developer Network Bug Database (http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4073756), by mailto:morgan.sziraki@cartesian.co.uk
The code is modified to protect against a situation where
To avoid this, we create the new file with a modified filename (prefixed by an underscore '_'). When the copying is complete, we rename the file to the desired name. This rename is within a directory, and therefore does not extend across NFS filesystem boundaries, so it should work!
Modify again to make sure that neither the destination file nor the temp file exist - throw an exception if they do. We can't rename on top of an existing file.
public static final void move(File fromFile, File toFile) throws IOException
Move a File
The renameTo method does not allow action across NFS mounted filesystems. This method is the workaround.
fromFile - The existing FiletoFile - The new FileIOException - if any problems occurCopyright © 2013 DuraSpace. All Rights Reserved.