Chapter TWENTY-FIVE
Files and Streams


Exam Objectives

Use Stream API with NIO.2.

Answers

1. The correct answer is A.
A value of zero for the maxDepth argument means that only the starting directory is visited (no files or subdirectories).


2. The correct answer is D.
Option A is false. Files.find() doesn't have a default subdirectory depth. This is passed as an argument to the method.
Option B is false. Files.find() follows symbolic links only if FileVisitOption.FOLLOW_LINKS is passed as an argument.
Option C is false. Files.walk() follows symbolic links only if FileVisitOption.FOLLOW_LINKS is passed as an argument.
Option D is true. Files.walk() traverses subdirectories recursively.


3. The correct answer is D.
Option A is not equivalent. Files.list() doesn't traverse subdirectories recursively.
Option B is not equivalent. Files.find() is missing the max depth argument.
Option C is not equivalent. The last argument must be a BiPredicate.


4. The correct answer is C.
If the file doesn't exist, Files.line(Path) throws an IOException (a java.nio.file.NoSuchFileException) when the method is called, before the stream is created.