public static List < String > readFileFromClassPathAsList ( String _fileName , Charset _charset , boolean _silent ) { List < String > contents = new ArrayList <> ( ) ; if ( StringUtil . isBlank ( _fileName ) ) { return contents ; } InputStream inputStream = FileIoUtil . class . getClassLoader ( ) . getResourceAsStream ( _fileName ) ; if ( inputStream != null ) { try ( BufferedReader dis = new BufferedReader ( new InputStreamReader ( inputStream , _charset ) ) ) { String s ; while ( ( s = dis . readLine ( ) ) != null ) { contents . add ( s ) ; } return contents ; } catch ( IOException _ex ) { if ( ! _silent ) { LOGGER . error ( "Error while reading resource to string: " , _ex ) ; } return null ; } } else { if ( _silent ) { return null ; } } return contents ; }
Reads a file from classpath to a list of String with the given charset . Will optionally suppress any exception logging .