Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fastest way to copy files in Java

Tags:

What ist the fastest way to copy a big number of files in Java. So far I have used file streams and nio. Overall streams seem to be faster than nio. What experiences did you make so far?

like image 988
Mato Avatar asked Oct 23 '10 15:10

Mato


People also ask

How can I copy multiple files faster?

Know Mouse Shortcuts for Faster Copying, TooHold Ctrl and click multiple files to select them all, no matter where they are on the page. To select multiple files in a row, click the first one, then hold Shift while you click the last one.

How do you copy a file in Java?

Another common way to copy a file with Java is by using the commons-io library. The latest version can be downloaded from Maven Central. Then, to copy a file we just need to use the copyFile() method defined in the FileUtils class. The method takes a source and a target file.

Is FastCopy faster than Windows copy?

FastCopy was about 16% faster than the Windows copy method. I then tried copying an 11.7 GB file in a different environment, one where file copies seem to take forever over the WAN. Using the normal Windows copy method, the 11.7 GB file copied across the WAN in 55 minutes. Using FastCopy, it copied in 51 minutes.


1 Answers

http://www.baptiste-wicht.com/2010/08/file-copy-in-java-benchmark/ might get you your answer.

For the benchmark, I made the tests using different files.

  1. Little file (5 KB)
  2. Medium file (50 KB)
  3. Big file (5 MB)
  4. Fat file (50 MB)
  5. And an enormous file (1.3 GB) only binary

And I made the tests first using text files and then using binary files. I made the tests using in three modes :

  1. On the same hard disk. It's an IDE Hard Disk of 250 GB with 8 MB of cache. It's formatted in Ext4.
  2. Between two disk. I used the first disk and an other SATA Hard Disk of 250 GB with 16 MB of cache. It's formatted in Ext4.
  3. Between two disk. I used the first disk and an other SATA Hard Disk of 1 TB with 32 MB of cache. It's formatted using NTFS.

I used a benchmark framework, described here, to make the tests of all the methods. The tests have been made on my personal computer (Ubuntu 10.04 64 bits, Intel Core 2 Duo 3.16 GHz, 6 Go DDR2, SATA Hard Disks). The Java version used is a Java 7 64 bits Virtual Machine...

like image 67
mihn Avatar answered Sep 22 '22 16:09

mihn