This is another way to do the same thing from java.io.File parameters. Here, i'm throwing the IOException and leaving the caller to handle it. Also, what is the point of calling System.exit() in the 'catch (FileNotFoundException )' block?
private static void copyfile(File srcFile, File dstFile) throws IOException { InputStream in = null; OutputStream out = null; try { in = new FileInputStream(srcFile); out = new FileOutputStream(dstFile); byte[] buf = new byte[1024]; int len; while ((len = in.read(buf)) > 0){ out.write(buf, 0, len); } } finally { if (in != null) { try { in.close(); } catch (IOException e) { } } if (out != null) { try { out.close(); } catch (IOException e) { } } } }
View All Comments
| View Tutorial