Looking for help with the following code:
package pkgPeople;
import java.io.File;
import java.io.FileOutputStream;
import java.io.ObjectOutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Scanner;
public class RetrieveNonSerializedFile {
public static void main(String[] args) throws Exception{
File inFile = new File("F:/CS9.27/friends2.dat");
Scanner reader = new Scanner(inFile);
while (reader.hasNextLine()){
String nm = reader.nextLine();
int height = reader.nextInt();
int weight = reader.nextInt();
double balance = reader.nextDouble();
long acctID = reader.nextInt();
System.out.println(nm + ":" + height + " inches " + weight + " pounds" + acctID + " account ID" + balance + "dollars");
/*writer.println(nm);
writer.println(height);
writer.println(weight);
writer.println(acctID);
writer.println(balance);*/
}
reader.close();
//writer.close();
}
}
When running the program, the exception
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Unknown Source)
at java.util.Scanner.next(Unknown Source)
at java.util.Scanner.nextInt(Unknown Source)
at java.util.Scanner.nextInt(Unknown Source)
at pkgPeople.RetrieveNonSerializedFile.main(RetrieveNonSerializedFile.java:22)
is thrown.
The friends2.dat is a data file that has the following.....
Jim is the name of the person.
13 inches is the height of Jim.
14 pounds is the weight of Jim
1234.650000 dollars is the balance of Jim
12345 is the ID of the bank account.
It is just a text file. Any help to get through the InputMismatch would be great. Thanks.