import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; /** * Uses a BufferedReader to read from a specified file into a given LineStorage. * * @author Alexander Schaap * * @param * word type */ public class Input2> extends InputAbstract { @Override public void parse(String filename) { BufferedReader r = null; try { r = new BufferedReader(new FileReader(filename)); String l; while ((l = r.readLine()) != null) { String[] line = l.split(" "); StorageInterface> words = new StorageObservableArrayList>(); for (int i = 0; i < line.length; i++) { words.add(wc.convert(line[i])); } ls.add(words); } } catch (FileNotFoundException e) { System.out.println("File not found"); e.printStackTrace(); } catch (IOException e) { System.out.println("Some IO error"); e.printStackTrace(); } finally { try { if (r != null) r.close(); } catch (IOException ex) { System.out.println("Couldn't close BufferedReader"); ex.printStackTrace(); } } } }