Copying a file in Java

February 17, 2010

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

posted in code-snippet by Stefan Kendall

Follow comments via the RSS Feed | Leave a comment | Trackback URL

1 Comment to "Copying a file in Java"

  1. Stefan Kendall wrote:

    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.

Leave Your Comment

 
Powered by Wordpress and MySQL. Theme by Shlomi Noach, openark.org