Skip to content

Instantly share code, notes, and snippets.

@K0NRAD
Last active October 13, 2015 12:56
Show Gist options
  • Save K0NRAD/8974721c1ca06ac139e6 to your computer and use it in GitHub Desktop.
Save K0NRAD/8974721c1ca06ac139e6 to your computer and use it in GitHub Desktop.
copy path recursivly with NIO
public void copyPath(Path source, Path target) throws IOException {
Files.walkFileTree(source, new SimpleFileVisitor<Path>() {
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
return copy(file);
}
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
return copy(dir);
}
private FileVisitResult copy(Path fileOrDir) throws IOException {
Files.copy(fileOrDir, target.resolve(source.relativize(fileOrDir)), StandardCopyOption.REPLACE_EXISTING);
return FileVisitResult.CONTINUE;
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment