public static List < String > readLines ( File file , Charset charset ) throws IOException { InputStream in = null ; try { in = new FileInputStream ( file ) ; if ( null == charset ) { return IOs . readLines ( new InputStreamReader ( in ) ) ; } else { InputStreamReader reader = new InputStreamReader ( in , charset . name ( ) ) ; return IOs . readLines ( reader ) ; } } finally { IOs . close ( in ) ; } }
Reads the contents of a file line by line to a List of Strings . The file is always closed .