Advanced file search

  • 28
  • Locked
Let's implement a configurable file search within a directory. Look over the java.nio.file.FileVisitor interface and its superclass's implementation java.nio.file.SimpleFileVisitor.
You can't complete this task, because you're not signed in.
Comments (2)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Justin Smith
Level 39 , Greenfield, USA, United States
30 July 2022, 13:25
The only thing that's tricky about this one is that we haven't seen FileVisitor before, and when you get to writing the visitFile method, your inclination will probably be to try to write the stuff that the class does automatically. Mainly, worrying about how to search through sub-directories and getting the lists of files in directories. Well, don't worry about that! 😁 Pretend that the Path file argument is the only thing you have to consider, write the code to evaluate that, and let the magic of FileVisitor do the rest! All three of the tasks on this page presented different approaches to searching file trees (assuming you used recursion for the first one, and a queue for the second one). FileVisitor is far and away the easiest option once you understand how it works!
Олег Байбула
Level 32 , Ukraine
10 March, 11:32
And there is a mess between nio and io.😱