Here you can find the source of copyDirectory(File sourceFile, File destFile)
private static void copyDirectory(File sourceFile, File destFile) throws IOException
//package com.java2s; // are made available under the terms of the Eclipse Public License v1.0 import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.nio.channels.FileChannel; public class Main { private static void copyDirectory(File sourceFile, File destFile) throws IOException { if (sourceFile.isDirectory()) { if (!destFile.exists()) { destFile.mkdir();/*from w w w. ja v a 2 s .c o m*/ } String files[] = sourceFile.list(); for (int i = 0; i < files.length; i++) { copyDirectory(new File(sourceFile, files[i]), new File(destFile, files[i])); } } else { if (!sourceFile.exists()) { //humf } else { copyFile(sourceFile, destFile); } } } private static void copyFile(File sourceFile, File destFile) throws IOException { if (!destFile.exists()) { destFile.createNewFile(); } FileChannel source = null; FileChannel destination = null; try { source = new FileInputStream(sourceFile).getChannel(); destination = new FileOutputStream(destFile).getChannel(); destination.transferFrom(source, 0, source.size()); } finally { if (source != null) { source.close(); } if (destination != null) { destination.close(); } } } }