Here you can find the source of copyFile(final File source, final File dest, final boolean overwrite)
public static void copyFile(final File source, final File dest, final boolean overwrite) throws IOException, FileNotFoundException
//package com.java2s; //License from project: Apache 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 { public static void copyFile(final File source, final File dest, final boolean overwrite) throws IOException, FileNotFoundException { if (dest.exists()) { if (overwrite) dest.delete();//from ww w . j ava 2 s . co m else return; } if (!dest.getParentFile().exists()) dest.getParentFile().mkdirs(); BufferedInputStream in = new BufferedInputStream(new FileInputStream(source)); ; BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(dest, true)); ; int bytes = 0; while ((bytes = in.read()) != -1) { out.write(bytes); } in.close(); out.close(); } }