Here you can find the source of copyFile(File sourceFile, File targetFile)
public static void copyFile(File sourceFile, File targetFile) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; public class Main { private static final int BUFFER = 8192; public static void copyFile(File sourceFile, File targetFile) throws IOException { BufferedInputStream inBuff = null; BufferedOutputStream outBuff = null; try {/*from w ww. j a va 2 s .c om*/ inBuff = new BufferedInputStream(new FileInputStream(sourceFile)); outBuff = new BufferedOutputStream(new FileOutputStream(targetFile)); byte[] buffer = new byte[BUFFER]; int length; while ((length = inBuff.read(buffer)) != -1) { outBuff.write(buffer, 0, length); } outBuff.flush(); } finally { if (inBuff != null) { inBuff.close(); } if (outBuff != null) { outBuff.close(); } } } }