public List < String > getFileAsList ( final String fileName , final String encoding ) throws IOException { LOG . info ( "Get file as list. file: " + fileName ) ; List < String > result = new ArrayList < String > ( ) ; BufferedReader reader = null ; try { reader = new BufferedReader ( new InputStreamReader ( new FileInputStream ( fileName ) , encoding ) ) ; String line = null ; while ( ( line = reader . readLine ( ) ) != null ) { result . add ( line ) ; } } finally { if ( reader != null ) { reader . close ( ) ; } } LOG . info ( "Returning: " + result ) ; return result ; }
This method returns the content of a file into a list of strings . Each file line will correspond to an element in the list . Please be careful when using this method as it is not intended to be used with large files