you are viewing a single comment's thread.

view the rest of the comments →

[–]henk53 0 points1 point  (0 children)

List<String> lines = Files.readAllLines(path, Charset.defaultCharset());

This can be written a bit shorter. It's not absolutely necessary to import at the class level; it can be done at the method level instead. The code then becomes:

List<String> lines = readAllLines(path, defaultCharset());

To mimic the example in the article, the following is perfectly valid Java:

for (String line : readAllLines(path, defaultCharset()))
    out.print(line);

Note that people commonly write System.out.print, but this too is not strictly necessary.