What is a better option (in terms of performance): copying a file using fileinputstream and fileoutputstream or running a OS specific command copy command from Java?
I'm quite sure using the OS specific copy command would be faster or at least as fast as a simple self-written solution. The OS specific command probably uses a sensible buffer size and other optimizations which you would otherwise have to figure out yourself.
Edit:
x-x is right, you should not call the copy command directly. I thought Java already had a copy method, like File.copy() or something, but I couldn't find anything, not even in JDIC. So Apache Commons IO is probably the way to go.
Do it in Java.
One problem with running an OS command is that you have to create a full process at the OS kernel level and that's a heavyweight operation. There is a large fixed overhead which will be particularly serious for smaller files.
The other problem is that it adds a system dependency without a good reason.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With