Skip to content

Instantly share code, notes, and snippets.

@arturotena
Created September 3, 2014 21:24
Show Gist options
  • Save arturotena/5408299567fa430cacc5 to your computer and use it in GitHub Desktop.
Save arturotena/5408299567fa430cacc5 to your computer and use it in GitHub Desktop.
Quick-and-dirty way to count the lines of Java source code of a project
// Quick-and-dirty way to count the lines of Java source code of a project
System.out.println(Files.walk(Paths.get("."))
.map(e -> e.toFile())
.filter(f -> f.isFile() && f.canRead())
.filter(f -> f.getName().endsWith(".java"))
.mapToLong(f -> {
try { return new BufferedReader(new FileReader( f )).lines().count();
} catch (Exception ex) { throw new RuntimeException(ex); }
})
.reduce(0, (acc, current) -> acc + current));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment