Created
May 17, 2017 15:12
-
-
Save douglascayers/a1ffbec636ad3fdf7b101f6d59f7126d to your computer and use it in GitHub Desktop.
Simple Java method to count all lines in a file. Requires Java 8+
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private static int getLineCount( File file ) throws Exception { | |
| try ( LineNumberReader reader = new LineNumberReader( new FileReader( file ) ) ) { | |
| while ( reader.readLine() != null ) {} | |
| return reader.getLineNumber(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment