Here you can find the source of copyFile(File in, File out)
public static void copyFile(File in, File out) 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 DEFAULT_BUFFER_SIZE = 16 * 1024; public static void copyFile(File in, File out) throws IOException { BufferedInputStream bis = null; BufferedOutputStream bos = null; try {/*from w w w . j a v a 2s .c o m*/ bis = new BufferedInputStream(new FileInputStream(in)); bos = new BufferedOutputStream(new FileOutputStream(out)); int available = bis.available(); available = available <= 0 ? DEFAULT_BUFFER_SIZE : available; int chunkSize = Math.min(DEFAULT_BUFFER_SIZE, available); byte[] buffer = new byte[chunkSize]; int byteread = 0; while ((byteread = bis.read(buffer)) > 0) { bos.write(buffer, 0, byteread); } } finally { if (bis != null) { bis.close(); } if (bos != null) { bos.close(); } } } }