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.
Use the excelent commons-io library, it has a method that will do exactly that. It is very widely used and rest assured it is very optimized.
Download it from here, or copy the POM dependency into your pom.xml file if using maven.
Don't copy with OS specific copy, it will not be portable. Using non-java code from java, whether with JNI or spawning an external command is a headache and maintenance nightmare.
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.
Depends on what you will do in case of errors. Often the native command is better capable of handling error situations, but you may have a hard time making it interact with the user.
A pure java solution (besides being cross platform) allows you to be fully in control - I would suggest using a library to handle the messy details and error situations.