Hello everyone. I am having difficulties with a program that I have been working on all day. I am trying to read a text file and read each line one at a time. Take that line and make an arraylist of the words of the line. then using the index of the arraylist define terms with it.
public class PCB {
public static void main(String arg[]) {
read();
}
public static ArrayList read() {
BufferedReader inputStream = null;
ArrayList<String> tokens = new ArrayList<String>();
try {
inputStream = new BufferedReader(new FileReader("processes1.txt"));
String l;
while ((l = inputStream.readLine()) != null) {
Scanner tokenize = new Scanner(l);
while (tokenize.hasNext()) {
tokens.add(tokenize.next());
}
return tokens;
}
} catch (IOException ioe) {
ArrayList<String> nothing = new ArrayList<String>();
nothing.add("error1");
System.out.println("error");
//return nothing;
}
return tokens;
}
}
The error I am getting is it only reads the first line. What am I doing wrong? Thank you so much in advance