September 2019
Intermediate to advanced
816 pages
18h 47m
English
In order to copy a file, we can rely on the Path copy(Path source, Path target, CopyOption options) throws IOException method. This method copies a file to the target file with the options parameter specifying how the copy is performed.
By combining the copy() method with a custom FileVisitor, we can copy an entire folder (including all its content). The stub code of this custom FileVisitor is listed as follows:
public class CopyFileVisitor implements FileVisitor { private final Path copyFrom; private final Path copyTo; ... private static void copySubTree( Path copyFrom, Path copyTo) throws IOException { Files.copy(copyFrom, copyTo, REPLACE_EXISTING, COPY_ATTRIBUTES); }}
Let's take a look at the main checkpoints and the ...