Here you can find the source of copyFile(File source, File destination)
public static void copyFile(File source, File destination) throws IOException
//package com.java2s; //License from project: Apache License import java.io.Closeable; 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 destination) throws IOException { if ((destination.getParentFile() != null) && (!destination.getParentFile().exists())) { destination.getParentFile().mkdirs(); }// www.ja v a2 s. c o m FileInputStream fis = null; FileOutputStream fos = null; try { fis = new FileInputStream(source); fos = new FileOutputStream(destination); byte[] buffer = new byte[1024 * 4]; int n = 0; while ((n = fis.read(buffer)) != -1) { fos.write(buffer, 0, n); } } finally { closeStream(fis); closeStream(fos); } } public static void closeStream(Closeable stream) { if (stream != null) { try { stream.close(); } catch (IOException e) { System.out.println("Failed to close stream !"); } } } }