public static String[] fileToArray(File file,String label){
  LinkedList<String> words=new LinkedList<>();
  words.add(label);
  BufferedReader in=openReader(file);
  for (String line=readLine(in,file); line != null; line=readLine(in,file)) {
    String[] lineWords=line.split("\\s+");
    for (    String lineWord : lineWords)     if (!lineWord.matches("^\\s*$"))     words.add(lineWord);
  }
  closeReader(in,file);
  return words.toArray(new String[words.size()]);
}

public static String [ ] fileToArray ( File file , String label ) { LinkedList < String > words = new LinkedList < > ( ) ; words . add ( label ) ; BufferedReader in = openReader ( file ) ; for ( String line = readLine ( in , file ) ; line != null ; line = readLine ( in , file ) ) { String [ ] lineWords = line . split ( "\\s+" ) ; for ( String lineWord : lineWords ) if ( ! lineWord . matches ( "^\\s*$" ) ) words . add ( lineWord ) ; } closeReader ( in , file ) ; return words . toArray ( new String [ words . size ( ) ] ) ; }
reads in the specified file , splits it on whitespace , and adds all resulting words to an array which it returns . the specified label string appears in the returned array first , before any of the file ' s words .
