Here you can find the source of copyFile(File sourceFile, File destinationFile)
public static void copyFile(File sourceFile, File destinationFile)
//package com.java2s; //License from project: Open Source License import java.io.*; import java.nio.channels.FileChannel; public class Main { public static void copyFile(File sourceFile, File destinationFile) { copyFile(sourceFile, destinationFile, true); }//from w ww . jav a 2s. c om public static void copyFile(File sourceFile, File destinationFile, boolean overwrite) { try { if (sourceFile.exists()) { if (!overwrite && destinationFile.exists()) { System.out.println("Destination file exists\n" + sourceFile.getAbsolutePath()); return; } if (!destinationFile.exists()) { destinationFile.createNewFile(); } FileChannel sourceStream = null, destinationStream = null; try { sourceStream = new FileInputStream(sourceFile).getChannel(); destinationStream = new FileOutputStream(destinationFile).getChannel(); destinationStream.transferFrom(sourceStream, 0, sourceStream.size()); } finally { if (sourceStream != null) { sourceStream.close(); } if (destinationStream != null) { destinationStream.close(); } } } else { System.out.println("Source file does not exist\n" + sourceFile.getAbsolutePath()); } } catch (IOException e) { e.printStackTrace(); } } }