Here you can find the source of copyFile(File sourceFile, File destFile)
public static void copyFile(File sourceFile, File destFile)
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.nio.channels.FileChannel; public class Main { public static void copyFile(File sourceFile, File destFile) { FileInputStream in = null; FileOutputStream out = null; FileChannel source = null; FileChannel destination = null; try {//from w w w .j a va 2 s.c o m destFile.createNewFile(); in = new FileInputStream(sourceFile); out = new FileOutputStream(destFile); source = in.getChannel(); destination = out.getChannel(); destination.transferFrom(source, 0, source.size()); } catch (IOException e) { e.printStackTrace(); } finally { try { if (source != null) source.close(); if (destination != null) destination.close(); if (in != null) in.close(); if (out != null) out.close(); } catch (IOException e) { e.printStackTrace(); } } } }