Counting Lines With Java 8

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

Path path = Paths.get(“./readme.txt”);
long lineCount = Files.lines(path).count();

==============================
Comments:

Wrong!

right:

try (Stream stream = Files.lines(path)) {
long lineCount = stream().count();
}

Leave a comment