I have text file has in each line date of person (Name, gender, age, weight)
David Smith
Male
32
85.83
Sarah Apple
Female
27
56.23
Teller Saimone
Male
29
87.71
Here is my code:
Scanner inputFile = new Scanner(myFile);
while (inputFile.hasNext()) {
Persone Pers = new Persone();
Pers.setVehicleMake(inputFile.nextLine());
System.out.println(Pers.getVehicleMake());
Pers.setVehicleModel(inputFile.nextLine());
System.out.println(Pers.getVehicleModel());
Pers.setNumberCylinders(inputFile.nextInt());
System.out.println(Pers.getNumberCylinders());
Pers.setEstMPG(inputFile.nextDouble());
System.out.println(Pers.getEstMPG());
auotList.add(Pers);
}
When I run the code I got this error:
run:
David Smith
Male
32
85.83Sarah Apple
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Scanner.java:864)
at java.util.Scanner.next(Scanner.java:1485)
at java.util.Scanner.nextInt(Scanner.java:2117)
at java.util.Scanner.nextInt(Scanner.java:2076)
at PersonDrive.main(PersonDrive.java:36)
/home/jaguar/.cache/netbeans/8.1/executor-snippets/run.xml:53: Java returned: 1
BUILD FAILED (total time: 1 second)
It seem when it do the loop for the next read it read whitespace