The program that we allowed when trying to move files from one directory to another. After a lot of debugging, I found an error by writing a small utility program that simply moves the file from one directory to another (code below). It turns out that when moving files around the local file system it works fine, an attempt to transfer the file to another file system fails.
Why is this? The question may be platform specific - we use Linux on ext3, if that matters.
And the second question; should I use something else than the renameTo() method of the File class? This seems to just work on local file systems.
Tests (run as root):
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
the 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")); } }
oligofren
source share