I need to write a program to copy some files from a folder to other folders on the systems.
I wrote a java program which creates a new thread for each destination folder. Each thread create a InputStream for each file and write it to destination folder [Using BufferedOutputStream(new FileOutputStream(targetFile))].
But it takes much more time then expected.
Is there any other way so that it takes less time?
Edited by: user12233794 on Nov 20, 2011 11:23 PM
If you show some code, we may be able to tell you how to improve it, like using buffered streams for input and output, using better buffer sizes, reading the file only once and writing it multiple times (if the file size is somehow predictable and reasonable), etc. You may also experiment with File.renameTo(), which probably delegates more of the work to the OS (but read carefully the documentation for that method).