What is the result of applying the Files.walkFileTree()
method to the current directory and an instance of the following FileVisitor class?
1: public class FilePrinter implements FileVisitor<Path> { 2: public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) 3: throws IOException { 4: System.out.println("Found file: "+file.getFileName()); 5: return FileVisitResult.CONTINUE; 6: } 7: }
D.
The code does not compile because in order to implement the FileVisitor interface, all four visitor methods must be provided, so D is correct.
If instead of implementing the FileVisitor interface, it extended the SimpleFileVisitor class, which does not require any methods to be overridden, then the code would compile and produce the list of file names in the directory tree, making B the correct answer.