Reading words and counting their occurence in Java I have very typical problem:

Given big text file, containing text. The task is to calculate occurence of each word and print this info from most occured to less.

Example input:

cat cat cat dog dog mouse


Correct answer:

cat -&gt; 3
dog -&gt; 2
mouse -&gt; 1


First I solved this using Scanner. But this solutions seems to be slow, cause IO was blocking.

After some time and cookie spent I wrote this solution:

final Path path = FileSystems.getDefault().getPath("/tmp/", "file.txt");

Map&lt;String, Long&gt; occ =
  Files
    .lines(path)
    .flatMap(line -&gt; Arrays.stream(line.split(delimRegex)))
    .filter(line -&gt; line.length() &gt; 0)
    .map(String::toLowerCase)
    .collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));

occ
  .entrySet()
  .stream()
  .sorted((e1, e2) -&gt; e2.getValue().compareTo(e1.getValue()))
  .forEach(e -&gt; System.out.println(e.getKey() + " -&gt; " + e.getValue()));


I think solution is good (but not sure). Is there any other optimization techniques I've ignored?
I have one comment: 
Files.lines() method has the following comment in the JDK documentation:


  The returned stream encapsulates a Reader. If timely disposal of file
  system resources is required, the try-with-resources construct should
  be used to ensure that the stream's close method is invoked after the
  stream operations are completed.


in other words, in order to prevent resource leak, you need to construct the stream in a try-with-resources block 

try (Stream&lt;String&gt; linesStream = Files.lines(path)) {
    Map&lt;String, Long&gt; occ = linesStream
        .flatMap(line -&gt; Arrays.stream(line.split(delimRegex)))
        ....
}