Hopefully someone has seen this before. I'm trying to copy all directory contents from the source to a different directory, and for this I started using the Commons FileUtils.copyDirectorytoDirectory method(File src, File dest). The code is pretty simple:
public static void copyDirtoDir(String src, String dest) {
File s = new File(src);
File d = new File(dest);
try {
FileUtils.copyDirectoryToDirectory(s, d);
} catch (IOException e) {
e.printStackTrace();
}
}
To run this test on Linux, I'm running the app as a JAR and passing the src and dest strings from the command line. The problem is that when I check the resulting directory size after execution, there's a huge difference in size (with the copied dir around twice the size of the original - checked using 'du -sh').
I then simply tried with nio.FileChannels, as follows:
public static void copyFile(File in, File out) throws IOException {
FileChannel source = new FileInputStream(in).getChannel();
FileChannel destination = new FileOutputStream(out).getChannel();
source.transferTo(0, source.size(), destination);
source.close();
destination.close();
}
Calling this method for every file inside the directory. The resulting size from this variation is also around twice the size of the original. If I do a listing of the directories' contents, they are the same.
Is there any missing parameter or something that could be causing this size difference?
Not sure what's going on, but you can use diff to diff directories. I'm sure that will pin down the differences easily.