public static List < String > readLines ( String filename ) { List < String > lines = Lists . newArrayList ( ) ; try { BufferedReader in = new BufferedReader ( new FileReader ( filename ) ) ; String line ; while ( ( line = in . readLine ( ) ) != null ) { // Ignore blank lines. if ( line . trim ( ) . length ( ) > 0 ) { lines . add ( line ) ; } } in . close ( ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } return lines ; }
Read the lines of a file into a list of strings with each line represented as its own string .