Reputation: 107
Is there an efficient way to copy a file in java to around 100 folders without having to use
private static void copyFileUsingJava7Files(File source, File dest)
throws IOException {
Files.copy(source.toPath(), dest.toPath());
}
100 times
Upvotes: 0
Views: 814
Reputation: 4923
No other option will be efficient other than simply using copy method.
Upvotes: 0
Reputation: 1577
I don't have a code sample for you but think the most efficient way would be to set up an Asynchronous operation to handle all the file copies.
You would still need to do something similar to what you have but it wouldn't wait for each one to complete like you would get with a standard loop. Send them out there asynchronously and let the operating system handle all the juggling of the tasks to get things done in the quickest possible way.
In addition to this, if you are copying a single file to multiple locations, you can read the file into memory, then copy the in-memory file to the destination. This will help avoid problems such as slow file reads and waiting for locked files that can happen when reading from disk.
Upvotes: 1