public static Set < String > getResourceWords ( String resourceFile , Class clazz ) { Assert . notNullOrEmptyTrimmed ( resourceFile , "Missing resource file!" ) ; Scanner scanner = null ; try { InputStream resource = clazz . getResourceAsStream ( resourceFile ) ; scanner = new Scanner ( resource , UTF_8 ) ; Set < String > list = new LinkedHashSet <> ( ) ; while ( scanner . hasNext ( ) ) { String next = scanner . next ( ) ; if ( next != null && next . trim ( ) . length ( ) > 0 ) { list . add ( next ) ; } } return list ; } catch ( Exception e ) { return null ; } finally { if ( scanner != null ) { scanner . close ( ) ; } } }
Loads resource as a set of Strings where each word is added to the set