Java SE 8 Programmer II — Question 136
Given that these files exist and are accessible:
/sports/info.txt
/sports/cricket/players.txt
/sports/cricket/data/ODI.txt
and given the code fragment:
int maxDepth =2;
Stream<Path> paths = Files.find(Paths.get("/sports"),
maxDepth,
(p, a) -> p.getFileName().toString().endsWith ("txt"),
FileVisitOption.FOLLOW_LINKS);
Long fCount = paths.count();
System.out.println(fCount);
Assuming that there are NO soft-link/symbolic links to any of the files in the directory structure, what is the result?
Answer options
- A. 1
- B. 2
- C. 3
- D. An Exception is thrown at runtime.
Correct answer: D
Explanation
The code attempts to find '.txt' files within a depth of 2, but since the paths specified do not contain any symbolic links, it leads to an unexpected condition, resulting in an exception being thrown at runtime. The other options suggest numeric counts of files found, which are not applicable since the program does not execute successfully.