All operating systems include the option to search for files that verify some conditions in your file system (for example, the name or part of the name, the date of modification, and so on). In our case, we're going to implement an algorithm that looks for a file with a predetermined name. Our algorithms will take the initial path to start the search and the file we're going to look for as input. The JDK provides the ability to walk a directory tree structure, so there should be no need to implement your own in the real world.
Both versions of the algorithm will share a common class to store the results of our search. We will call this class
Result and it will have two attributes: a
Boolean value named
found that determines if we have found the file we were looking for and a
String value named
path with the full path of the file if we have found it.
The code for this class is very simple so it won't be included here.