Last active
October 13, 2015 12:56
-
-
Save K0NRAD/8974721c1ca06ac139e6 to your computer and use it in GitHub Desktop.
copy path recursivly with NIO
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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