Here you can find the source of copyDirectory(File source, File target)
private static void copyDirectory(File source, File target) throws IOException
//package com.java2s; //License from project: Apache License import java.io.*; public class Main { private static void copyDirectory(File source, File target) throws IOException { if (!target.exists()) { target.mkdir();/* w w w.j a va2 s . c om*/ } for (String f : source.list()) { copy(new File(source, f), new File(target, f)); } } public static boolean copy(File sourceLocation, File targetLocation) throws IOException { if (sourceLocation.exists() == false) { return false; } if (sourceLocation.isDirectory()) { copyDirectory(sourceLocation, targetLocation); } else { copyFile(sourceLocation, targetLocation); } return true; } private static void copyFile(File source, File target) throws IOException { try (InputStream in = new FileInputStream(source); OutputStream out = new FileOutputStream(target)) { byte[] buf = new byte[1024]; int length; while ((length = in.read(buf)) > 0) { out.write(buf, 0, length); } } } }