Scanner s = new Scanner(new File("src/mail_list"));
while (s.hasNextLine()){
String line1 = s.nextLine();
if (line1.startsWith("Users")){
line1 = s.nextLine();
while (!(line1 = s.nextLine()).isEmpty()) {
String arr[] = line1.split(" ", 4);
users.add(new User(arr[0],arr[1],arr[2],arr[3]));
}
}
if (line1.startsWith("Lists")){
line1 = s.nextLine();
while (!(line1 = s.nextLine()).isEmpty()) { //exception here
String arr1[] = line1.split(" ", 2);
ArrayList<String> tmp = new ArrayList<String>();
StringTokenizer st = new StringTokenizer(arr1[1]);
while (st.hasMoreTokens()) {
tmp.add(st.nextToken());
}
list.add(new List((arr1[0]), tmp));
}
}
}
/*-testfile-start*/
Keyword: Users
username1 Name1 Surname1 email1
username2 Name2 Surname2 email2
Keyword: Lists
list_name username1 username2 ...
/*-testfile-end*/
I'm using the above code in order to sort things from the above testfile pattern. Basically it means that if I encounter the keyword "Users" I have to add the said info about the user.
I marked in the code where the exception rises. Any ideas on how to counter it?