Here you can find the source of copyFile(FileChannel srcFc, File dstFile)
public static long copyFile(FileChannel srcFc, File dstFile) throws IOException
//package com.java2s; //License from project: LGPL import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; public class Main { public static long copyFile(FileChannel srcFc, File dstFile) throws IOException { long r = 0; FileOutputStream fos = new FileOutputStream(dstFile); try {/* w w w .j a v a2s . c om*/ ByteBuffer bb = ByteBuffer.allocate(32768); for (int n; (n = srcFc.read(bb)) != -1;) { bb.flip(); fos.write(bb.array(), 0, bb.limit()); bb.clear(); r += n; } } finally { fos.close(); } return r; } public static long copyFile(File srcFile, File dstFile) throws IOException { FileInputStream fis = new FileInputStream(srcFile); try { return copyFile(fis.getChannel(), dstFile); } finally { fis.close(); } } }