Here you can find the source of copyFile(File source, File dest)
public static void copyFile(File source, File dest)
//package com.java2s; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; public class Main { public static void copyFile(File source, File dest) { if (!isValidFile(source)) return; FileInputStream in = null; FileOutputStream out = null; byte[] buffer = new byte[1024 * 64]; //64K int bytesRead = -1; try {// ww w . ja v a 2 s .com in = new FileInputStream(source); out = new FileOutputStream(dest); while ((bytesRead = in.read(buffer)) != -1) { out.write(buffer, 0, bytesRead); } } catch (Exception e) { e.printStackTrace(); } finally { try { in.close(); } catch (IOException e) { e.printStackTrace(); } try { out.close(); } catch (IOException e) { e.printStackTrace(); } } } public static boolean isValidFile(String file) { return isValidFile(new File(file)); } public static boolean isValidFile(File file) { return file.exists() ? file.isFile() : false; } }