Copying files in Java

What is the best option (in terms of performance): copying a file using fileinputstream and fileoutputstream or running a command to copy specific OS commands from Java?

+3
source share
4 answers

I’m sure that using the copy command of a particular OS will be faster or at least as fast as a simple self-recording solution. The particular OS command probably uses a reasonable buffer size and other optimizations that you would otherwise have to figure out yourself.

Edit:
xx is correct, you should not invoke the copy command directly. I thought Java already has a copy method like File.copy () or something else, but I couldn't find anything, even in JDIC. So Apo Commons IO is probably the way to go.

+2
source

Use the excelent commons-io library, it has a method that will do just that. It is very widely used and is sure that it is very optimized.

Download it from here or copy the POM dependency to the pom.xml file when using maven .

, . -java- java, JNI , .

+2

Java.

, . , .

, .

+2

, . , .

A pure java solution (in addition to the cross platform) allows you full control - I would suggest using a library to handle messy parts and error situations.

+1
source

Source: https://habr.com/ru/post/1716551/


All Articles