Good evening,
I need to read some lines from a file, the file is csv and the file is structured like so:
4,
Mo Farah,30,
Jessica Ennis,27,
i need to read those values and put them into variables, that's how i tried to do this:
while(nextline != null){
StringTokenizer st = new StringTokenizer(nextline,",");
int size = Integer.parseInt(st.nextToken());
System.out.println(size);
nextline = reader.readLine();
StringTokenizer st2 = new StringTokenizer(nextline, ","); //why???
String name = st2.nextToken();
System.out.println(name);
int age = Integer.parseInt(st2.nextToken());
System.out.println(age);
the first int (4) is read just fine, however if i want to move to the next line it throws a noSuchElementException, so i had to write the line next to "//why???" in order to move to the next line, do i really have to instantiate a new tokenizer each time i want to move to the next line? or is there a better way of doing this?
Thank you very much