Code snippet. Why isn’t this part of the Java API?
Just use commons.
<dependency> <groupId>commons-io</groupId> <artifactId>commons-io</groupId> <version>1.4</version> </dependency>
FileUtils gives us this:
public static void copyFile(File srcFile, File destFile) throws IOException
In case fromStream.close() throws an exception, you should probably also catch that to close toStream. All of these seems pretty absurd, though, and it makes me long for a “with” statement in Java.
Link | February 17th, 2010 at 4:40 pm