title: Java fails in moving (renaming) a file when the resulting file is on another filesystem
body: <p>A program we have erred when trying to move files from one directory to another. After much debugging I located the error by writing a small utility program that just moves a file from one directory to another (code below). It turns out that while moving files around on the local filesystem works fine, trying to move a file to another filesystem fails. </p>
  
  <p>Why is this? The question might be platform specific - we are running Linux on ext3, if that matters. </p>
  
  <p>And the second question; should I have been using something else than the <code>renameTo()</code> method of the <code>File</code> class? It seems as if this just works on local filesystems.</p>
  
  <p>Tests (run as root):</p>
  
  <pre><code>touch /tmp/test/afile
  
  java FileMover /tmp/test/afile /root/
  The file move was successful
  
  touch /tmp/test/afile
  
  java FileMover /tmp/test/afile /some_other_disk/
  The file move was erroneous
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>import java.io.File;
  
  public class FileMover {
      public static void main(String arguments[] ) throws Exception {
          boolean success;
          File file = new File(arguments[0]);
          File destinationDir = new File(arguments[1]);
          File destinationFile = new File(destinationDir,file.getName() );
          success = file.renameTo(destinationFile);
          System.out.println("The file move was " + (success?"successful":"erroneous"));
      }
  }
  </code></pre>