Here you can find the source of copyRecursively(File src, File dest)
public static void copyRecursively(File src, File dest) throws IOException
//package com.java2s; // The MIT License (MIT) import java.io.File; import java.io.IOException; import java.nio.file.FileVisitResult; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.SimpleFileVisitor; import java.nio.file.attribute.BasicFileAttributes; public class Main { public static void copyRecursively(File src, File dest) throws IOException { copyRecursively(src.toPath(), dest.toPath()); }/*from ww w .ja v a 2 s.c om*/ public static void copyRecursively(Path src, Path dest) throws IOException { BasicFileAttributes srcAttr = Files.readAttributes(src, BasicFileAttributes.class); if (srcAttr.isDirectory()) { Files.walkFileTree(src, new SimpleFileVisitor<Path>() { @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { Files.createDirectories(dest.resolve(src.relativize(dir))); return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Files.copy(file, dest.resolve(src.relativize(file))); return FileVisitResult.CONTINUE; } }); } else if (srcAttr.isRegularFile()) { Files.copy(src, dest); } else { throw new IllegalArgumentException("src must denote a directory or file"); } } }