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; import java.io.*; public class Main { private final static int BUFFER = 8192; public static void copyFile(File sourceFile, File targetFile) throws IOException { BufferedInputStream inBuff = null; BufferedOutputStream outBuff = null; if (null != sourceFile && null != targetFile) { try { inBuff = new BufferedInputStream(new FileInputStream( sourceFile));//from w w w .ja va2 s. c o m 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(); } } } } }