Here you can find the source of copyFile(final File source, final File destination)
public static void copyFile(final File source, final File destination) throws FileNotFoundException, 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.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; public class Main { /**/*from w ww . j a va 2 s . c om*/ * Copy the source file to the destination file. The destination file will be deleted first before copying starts. */ public static void copyFile(final File source, final File destination) throws FileNotFoundException, IOException { if (source == null) { throw new NullPointerException("Source is null"); } if (destination == null) { throw new NullPointerException("Destination is null"); } if (source.exists() == false) { throw new NullPointerException("Source file not found."); } FileInputStream fio = null; BufferedInputStream bio = null; FileOutputStream fos = null; BufferedOutputStream bos = null; final byte[] buffer; try { if (destination.exists()) { destination.delete(); } fio = new FileInputStream(source); bio = new BufferedInputStream(fio); fos = new FileOutputStream(destination); bos = new BufferedOutputStream(fos); buffer = new byte[1024]; int b = bio.read(buffer); while (b != -1) { bos.write(buffer, 0, b); b = bio.read(buffer); } } finally { if (bio != null) { bio.close(); } if (bos != null) { bos.flush(); bos.close(); } if (fos != null) { fos.close(); } if (fio != null) { fio.close(); } } } }