Assuming the path referenced below exists and contains a symbolic link that references /again, what is the expected result of executing the following code snippet?
System.out.print(Files.walk(Paths.get("/again/and/again")).count());
B.
A cycle is caused when a path contains a symbolic link that references the path itself, or a parent of the parent, triggering an infinitely deep traversal.
That said, Files.walk()
does not follow symbolic links by default.
The cycle is never activated, and the code would print a number at runtime, making Option B the correct answer.
If the FOLLOW_LINKS enum value was used in the call to Files.walk()
, then it would trigger a cycle resulting in a FileSystemLoopException at runtime, and Option A would be the correct answer.