I'm trying to read a file, and put that information into an array as an object "Train" however I keep getting an InputMismatchException
The file is structured like this:
650
10
Train
23 40
12 09
Train2
02 24
12 15
(and so on).
How do I properly read the file to put the info in the array?
public void fillArray(String info){
try{
File f = new File(info);
Scanner console = new Scanner(f);
distance = console.nextInt();
int totalTrains = console.nextInt();
//console.nextLine();
for(int i = 0;i<totalTrains;i++){
String trainName = console.nextLine();
Time arrival = new Time(console.nextInt(),console.nextInt());
Time departure = new Time(console.nextInt(),console.nextInt());
trains[i]= new Train(trainName, departure, arrival, distance);
console.nextLine();
}
}catch (FileNotFoundException e){
System.out.println("Cannot locate File");
}
}