I am having trouble with this method. The method is supposed to read a text file for a series of data (Attack ID [int], date [String saved in the format MM/DD/YYYY], name of monster [String], location [String], and reporter of the attack [String])separated by commas and put those values into an ArrayList called monsterAttacks. Every time I run this method I get an InputMismatchException. I have a feeling it has something to do with the date but I'm not sure where or how to use the String split() method in this case. How can I make this work properly?
Disclaimer: This is part of a homework assignment.
Thanks in advance.
Edit: Sample Data from text file:
23,12/23/1994,Dracula,California,Trisha Takinawa
25,11/12/1992,Godzilla,New York,David
private void readFromFile(){
if(!(monsterAttacks.isEmpty())) {
monsterAttacks.clear();
System.out.println("\nList cleared...");
}
System.out.println("Enter path: ");
String pathName = getUserInput();
File file = new File(pathName);
Scanner read;
MonsterAttack attack;
try {
read = new Scanner(file);
do {
int id = read.nextInt();
String date = read.next();
String name = read.next();
String location = read.next();
String reporter = read.next();
attack = new MonsterAttack(id, date, name, location, reporter);
monsterAttacks.add(attack);
} while (read.hasNext());
read.close();
} catch(IOException e){
e.printStackTrace();
}
}