@Test public void testCopyFile() throws Exception { File source = new File(testRootDir, "soruce"); String target = testRootDir + File.separator + "dest"; IOTinyUtils.writeStringToFile(source, "testCopyFile", RemotingHelper.DEFAULT_CHARSET); IOTinyUtils.copyFile(source.getCanonicalPath(), target); File dest = new File(target); assertTrue(dest.exists()); }
static public void copyFile(String source, String target) throws IOException { File sf = new File(source); if (!sf.exists()) { throw new IllegalArgumentException("source file does not exist."); } File tf = new File(target); tf.getParentFile().mkdirs(); if (!tf.exists() && !tf.createNewFile()) { throw new RuntimeException("failed to create target file."); } FileChannel sc = null; FileChannel tc = null; try { tc = new FileOutputStream(tf).getChannel(); sc = new FileInputStream(sf).getChannel(); sc.transferTo(0, sc.size(), tc); } finally { if (null != sc) { sc.close(); } if (null != tc) { tc.close(); } } }
IOTinyUtils { static public void copyFile(String source, String target) throws IOException { File sf = new File(source); if (!sf.exists()) { throw new IllegalArgumentException("source file does not exist."); } File tf = new File(target); tf.getParentFile().mkdirs(); if (!tf.exists() && !tf.createNewFile()) { throw new RuntimeException("failed to create target file."); } FileChannel sc = null; FileChannel tc = null; try { tc = new FileOutputStream(tf).getChannel(); sc = new FileInputStream(sf).getChannel(); sc.transferTo(0, sc.size(), tc); } finally { if (null != sc) { sc.close(); } if (null != tc) { tc.close(); } } } }
IOTinyUtils { static public void copyFile(String source, String target) throws IOException { File sf = new File(source); if (!sf.exists()) { throw new IllegalArgumentException("source file does not exist."); } File tf = new File(target); tf.getParentFile().mkdirs(); if (!tf.exists() && !tf.createNewFile()) { throw new RuntimeException("failed to create target file."); } FileChannel sc = null; FileChannel tc = null; try { tc = new FileOutputStream(tf).getChannel(); sc = new FileInputStream(sf).getChannel(); sc.transferTo(0, sc.size(), tc); } finally { if (null != sc) { sc.close(); } if (null != tc) { tc.close(); } } }  }
IOTinyUtils { static public void copyFile(String source, String target) throws IOException { File sf = new File(source); if (!sf.exists()) { throw new IllegalArgumentException("source file does not exist."); } File tf = new File(target); tf.getParentFile().mkdirs(); if (!tf.exists() && !tf.createNewFile()) { throw new RuntimeException("failed to create target file."); } FileChannel sc = null; FileChannel tc = null; try { tc = new FileOutputStream(tf).getChannel(); sc = new FileInputStream(sf).getChannel(); sc.transferTo(0, sc.size(), tc); } finally { if (null != sc) { sc.close(); } if (null != tc) { tc.close(); } } }  static String toString(InputStream input, String encoding); static String toString(Reader reader); static long copy(Reader input, Writer output); static List<String> readLines(Reader input); static void copyFile(String source, String target); static void delete(File fileOrDir); static void cleanDirectory(File directory); static void writeStringToFile(File file, String data, String encoding); }
IOTinyUtils { static public void copyFile(String source, String target) throws IOException { File sf = new File(source); if (!sf.exists()) { throw new IllegalArgumentException("source file does not exist."); } File tf = new File(target); tf.getParentFile().mkdirs(); if (!tf.exists() && !tf.createNewFile()) { throw new RuntimeException("failed to create target file."); } FileChannel sc = null; FileChannel tc = null; try { tc = new FileOutputStream(tf).getChannel(); sc = new FileInputStream(sf).getChannel(); sc.transferTo(0, sc.size(), tc); } finally { if (null != sc) { sc.close(); } if (null != tc) { tc.close(); } } }  static String toString(InputStream input, String encoding); static String toString(Reader reader); static long copy(Reader input, Writer output); static List<String> readLines(Reader input); static void copyFile(String source, String target); static void delete(File fileOrDir); static void cleanDirectory(File directory); static void writeStringToFile(File file, String data, String encoding);  }