Using ArrayList to store Lines in a text File
Hey Guys,
I have the following program that I am using to read a text file and store each word in each line in an ArrayList. But I am getting the following error;
Exception in thread"main" java.util.ConcurrentModificationException
at java.util.AbstractList$Itr.checkForComodification(AbstractList.java:449)
at java.util.AbstractList$Itr.next(AbstractList.java:420)
at bus.OrderReader.parseLine(OrderReader.java:50)
at bus.OrderReader.main(OrderReader.java:32)
The code is as follows;
package bus;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.Scanner;
import java.util.Collection;
import java.util.ArrayList;
import java.util.Iterator;
publicclass OrderReader{
static Collection bread =new ArrayList();
static Collection filling =new ArrayList();
static Iterator iter1 = filling.iterator();
static Iterator iter2 = bread.iterator();
privatestaticint counter;
publicstaticvoid main(String args[]){
Scanner s =null;
try{
s =new Scanner(new BufferedReader(new FileReader("/Users/admin/Documents/workspace2/OBS/WebContent/WriteMe.txt")));
s.useDelimiter("\r");
while(s.hasNext()){
parseLine(s.next());
counter++;
}
s.close();
}
catch(FileNotFoundException e){
System.out.println("cannot find the file");
//ignore for now
}
}
publicstaticvoid parseLine(String line){
Scanner lineScanner =new Scanner(line);
lineScanner.useDelimiter("#");
bread.add(lineScanner.next());
filling.add(lineScanner.next());
System.out.println(iter1.next());
System.out.println(iter2.next());
}
}
I do not understand why this does not work. Can someone please point me in the right direction?
Thank You
Jaz

