Here you can find the source of copyFile(File sourceFile, File targetFile)
public static void copyFile(File sourceFile, File targetFile)
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.nio.channels.FileChannel; public class Main { public static void copyFile(File sourceFile, File targetFile) { FileInputStream source;/*from w w w . ja v a 2 s. c om*/ FileOutputStream destination; try { source = new FileInputStream(sourceFile); destination = new FileOutputStream(targetFile); FileChannel sourceFileChannel = source.getChannel(); FileChannel destinationFileChannel = destination.getChannel(); long size = sourceFileChannel.size(); sourceFileChannel.transferTo(0, size, destinationFileChannel); sourceFileChannel.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }