public static List < String > linesFromFile ( String filename , String encoding ) { try { List < String > lines = new ArrayList < String > ( ) ; BufferedReader in = new BufferedReader ( new EncodingFileReader ( filename , encoding ) ) ; String line ; while ( ( line = in . readLine ( ) ) != null ) { lines . add ( line ) ; } in . close ( ) ; return lines ; } catch ( IOException e ) { e . printStackTrace ( ) ; return null ; } }
Returns the contents of a file as a list of strings . The list may be empty if the file is empty . If there is an IOException it is caught and null is returned . Encoding can also be specified