Here is a code snippet that explain how to copy a file using IOUtils. You can get Apache IOUtils at
http://commons.apache.org/io/download_io.cgi
InputStream in = null;
OutputStream out = null;
try {
// Ensure folder is created
FileUtils.forceMkdir(new File("/Users/yann/myfolder"));
in = new FileInputStream(new File("/Users/yann/from.txt"));
out = new FileOutputStream(new File("/Users/yann/myfolder", "to.txt"));
IOUtils.copy(in, out);
} finally {
IOUtils.closeQuietly(in);
IOUtils.closeQuietly(out);
}
Thanks for the example. This is the simplest, most direct example I have ever seen... I like it that way.
ReplyDelete