I'm trying to read a .adi
file that has a line format of String
, Int
and Double
.
For example:
Ford,Fusion,2010,85254,12855.58
For the code, I'm required to use a try-catch
statement and the method header has to throw the exception. Furthermore, I have a while
statement inside the try block to process the data, however I keep getting the InputMismatchException
thrown.
So it looks like:
try{
Scanner scan = new Scanner(inventoryFile)
scan.useDelimiter(FIELD_SEPARATOR);
while(scan.hasNext()) {
String make = scan.next();
String model = scan.next();
int year = scan.nextInt();
int mileage = scan.nextInt();
double price = scan.nextDouble();
Automobile auto = new Automobile(make, model, year, mileage, price);
fileInventory.add(auto);
}
May I know how to resolve this issue? Thanks in advance.