In Tutorials > The Java I/O API > File System Basics > Walking the File Tree, "Kickstarting the Process" section, the second code listing includes the following:
Finder finder = new Finder(pattern);
Files.walkFileTree(startingDir, opts, Integer.MAX_VALUE, finder);
This code seems to be intended to be used with the Finder class in the "The Find Example" introduced much further down the page. This was not clear to me, at first.
It would be more intuitive from a learning perspective, in my opinion, to re-use the PrintFiles class here which has already be introduced, rather than use a class from code that the reader has likely not seen yet.
So it would instead be: Files.walkFileTree(startingDir, opts, Integer.MAX_VALUE, pf); (pf being the previously used PrintFiles instance).
As somebody who likes to learn by typing and executing code examples rather than just reading, using the PrintFiles class that I had already typed out was straightforward and worked well enough for the purpose but it was not clear to me for a while that the Finder class was defined later in the tutorial.
Introducing the Finder class at this point in the article, without explanation, the novice will likely not understand to what class the code refers and it may appear wrongly to them to be part of the built-in Java API.
~
On a related issue, the same code example should probably include import static java.nio.file.FileVisitOption.*; given the inclusion of EnumSet<FileVisitOption> opts = EnumSet.of(FOLLOW_LINKS); in this example, or at least make mention of it, as FOLLOW_LINKS is a new element to the code.
Thanks.
In Tutorials > The Java I/O API > File System Basics > Walking the File Tree, "Kickstarting the Process" section, the second code listing includes the following:
This code seems to be intended to be used with the
Finderclass in the "The Find Example" introduced much further down the page. This was not clear to me, at first.It would be more intuitive from a learning perspective, in my opinion, to re-use the
PrintFilesclass here which has already be introduced, rather than use a class from code that the reader has likely not seen yet.So it would instead be:
Files.walkFileTree(startingDir, opts, Integer.MAX_VALUE, pf);(pfbeing the previously usedPrintFilesinstance).As somebody who likes to learn by typing and executing code examples rather than just reading, using the
PrintFilesclass that I had already typed out was straightforward and worked well enough for the purpose but it was not clear to me for a while that theFinderclass was defined later in the tutorial.Introducing the Finder class at this point in the article, without explanation, the novice will likely not understand to what class the code refers and it may appear wrongly to them to be part of the built-in Java API.
~
On a related issue, the same code example should probably include
import static java.nio.file.FileVisitOption.*;given the inclusion ofEnumSet<FileVisitOption> opts = EnumSet.of(FOLLOW_LINKS);in this example, or at least make mention of it, asFOLLOW_LINKSis a new element to the code.Thanks.