For this homework, you will create a class that finds all the text files (not directories) that end in the .txt
or .text
extension (case-insensitive).
You must use streams and lambda functions for this assignment. You cannot use the File
class!
This homework assignment makes sure you understand how to use a functional approach for listing directories.
You are not required to use a functional approach in your project. In Java, a functional approach does not work well with mutability and exception handling. However, there are a few places it can be used. If you are interested, reach out to the instructor!
Below are some hints that may help with this homework assignment:
If you are more comfortable with anonymous classes and the File
class, start there. You will fail some of the tests, but you will be able to see whether you are finding the expected text files. Then, convert one thing at a time to use what is required.
Check out the Files
class in Java. The walk(...)
or find(...)
methods may be helpful here.
Use the FileVisitOption.FOLLOW_LINKS
option when using the walk(...)
or find(...)
method to follow symbolic links. Symbolic links (Unix) are essentially shortcuts (Windows) or aliases (MacOS) to other files.
<aside> <img src="/icons/warning_gray.svg" alt="/icons/warning_gray.svg" width="40px" /> If symbolic links (or shortcuts) cannot be created on your system, this test will be skipped locally. However, this test will be run by GitHub Actions!
</aside>
Be careful about where you use a try
-with-resources block with this assignment. It will auto-close resources, including streams, which may not always be what you want!
These hints are optional. There may be multiple approaches to solving this homework.