I wanted to post this small piece of code for those who are looking for it. Copying file contents using Streams is old way of doing, Java New IO is the way to go; using Java NIO is better in terms of performance. Following is the code to do file copy using Java NIO. public static void copyFile(File src, File dest) throws IOException { if (!src.exists()) { // either return quietly OR throw an exception return; } if (!dest.exists()) { dest.createNewFile(); } FileChannel source = new FileInputStream(src).getChannel(); try { FileChannel destination = new FileOutputStream(dest).getChannel(); try { ...
A techie who love to read, code and share ...