public final class CopyFileVisitor extends SimpleFileVisitor<Path>
FileVisitor which will create a copy of a directory
and its contents.
Example usage:
Files.walkFileTree(dir, new CopyFileVisitor(target);
| Constructor and Description |
|---|
CopyFileVisitor(Path target,
CopyOption... options)
Constructs a new
CopyFileVisitor which will copy the visited
file paths to the specified target directory. |
| Modifier and Type | Method and Description |
|---|---|
FileVisitResult |
preVisitDirectory(Path dir,
BasicFileAttributes attrs) |
FileVisitResult |
visitFile(Path file,
BasicFileAttributes attrs) |
postVisitDirectory, visitFileFailedpublic CopyFileVisitor(Path target, CopyOption... options)
CopyFileVisitor which will copy the visited
file paths to the specified target directory.
Note: The target directory must not exist since the visitor will also copy the root directory to the specified location.
target - The path to copy the visited files tooptions - Optional options for the copy operationspublic FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException
preVisitDirectory in interface FileVisitor<Path>preVisitDirectory in class SimpleFileVisitor<Path>IOExceptionpublic FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException
visitFile in interface FileVisitor<Path>visitFile in class SimpleFileVisitor<Path>IOException