Here you can find the source of copy2(String sourceFileName, String destFileName)
public static void copy2(String sourceFileName, String destFileName) throws Exception
//package com.java2s; import java.io.*; import java.nio.channels.FileChannel; public class Main { private final static int MB = 1048576; public static void copy2(String sourceFileName, String destFileName) throws Exception { FileInputStream in = new FileInputStream(sourceFileName); FileOutputStream out = new FileOutputStream(destFileName); FileChannel inC = in.getChannel(); FileChannel outC = out.getChannel(); while (inC.position() < inC.size()) { inC.transferTo(inC.position(), MB, outC); inC.position(inC.position() + MB); }/*from w w w .j a va 2s. co m*/ inC.close(); outC.close(); in.close(); out.close(); } }