With Java 8, file IO became a pleasure to work with. It was a drastic break from the old verbose syntax and awkward ((line = in.readLine()) != null) and try/try/close idioms. With the new Stream based methods and lambda functions, the IO API becomes more similar to Python in ease of use.
In the code snippet below, all the lines of a file is read, sorted, and printed.
The following lines do the same, but break up the in-line method invocations and returned objects, to more clearly see what’s going on.
Traversing the directory hierarchy is similarly easy and compact:
Finally, here’s an idea for an assertFileEquals() method. It takes two file names, one which is the expected “golden” file which would contain the output from the test. (The example file names below are to make sure the test passes).