Here you can find the source of copyFile(String src, String dest)
public static boolean copyFile(String src, String dest)
//package com.java2s; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.nio.channels.FileChannel; public class Main { public static boolean copyFile(String src, String dest) { return copyFile(new File(src), new File(dest)); }/*from w w w .j a va 2 s. com*/ public static boolean copyFile(File src, File dest) { boolean success = false; try { if (src.getCanonicalPath().contentEquals(dest.getCanonicalPath())) { System.err.println("cp: same file: " + src + " = " + dest); } else { FileChannel sourceChannel = new FileInputStream(src).getChannel(); FileChannel destinationChannel = new FileOutputStream(dest).getChannel(); sourceChannel.transferTo(0, sourceChannel.size(), destinationChannel); sourceChannel.close(); destinationChannel.close(); success = true; } } catch (Exception e) { System.err.println(e); e.printStackTrace(); } return success; } }