Here you can find the source of copyDir(Path from, Path to, IProgressMonitor monitor)
private static void copyDir(Path from, Path to, IProgressMonitor monitor) throws IOException
//package com.java2s; //License from project: Apache License import java.io.IOException; import java.nio.file.FileAlreadyExistsException; import java.nio.file.FileVisitOption; 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; import java.util.EnumSet; import org.eclipse.core.runtime.IProgressMonitor; public class Main { private static void copyDir(Path from, Path to, IProgressMonitor monitor) throws IOException { Files.walkFileTree(from, EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, new SimpleFileVisitor<Path>() { @Override//from w w w. j ava 2 s. c o m public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { Path targetdir = to.resolve(from.relativize(dir)); try { Files.copy(dir, targetdir); monitor.subTask(dir.toString()); monitor.worked(1); } catch (FileAlreadyExistsException e) { if (!Files.isDirectory(targetdir)) throw e; } return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Files.copy(file, to.resolve(from.relativize(file))); monitor.subTask(file.toString()); monitor.worked(1); return FileVisitResult.CONTINUE; } }); } }