private static void copyFile(File from, File to) throws IOException{ FileChannel out = null; FileChannel in = null; try { in = new FileInputStream(from).getChannel(); out = new FileOutputStream(to).getChannel(); final long length = in.size(); final long copied = in.transferTo(0, in.size(), out); if (copied != length) { throw new IOException("Could not transfer all bytes."); } } finally { Cleanly.close(out); Cleanly.close(in); } }
public static void copyResource(File outputDir, Class forClassLoader, String... names) throws IOException { for (String name : names) { InputStream is = locateResource(forClassLoader, name); try { unzipFile(outputDir, is, name); } finally { Cleanly.close(is); } } }