The previous two posts in my NIO.2 cookbook series presented simple recipes for copying and moving files, deleting files and directories, working with paths and attributes, and performing various testing operations. This article ends this series by presenting a more advanced file-copying recipe as well as advanced recipes for finding files and watching directories.
Copying Files, Part 2
Q: Can you expand Part 1's file-copying application, which copies a file to another file, to also copy a file to a directory and a directory hierarchy to another hierarchy?
A: Listing 1 presents the source code to an application that accomplishes all three file-copy operations. This application relies on NIO.2's file-visiting feature to walk the file/directory tree.