Не удается прочитать файл. Программа палает с InputMismatchException
на 4 строке файла. При том, что 3 и 4 строки идентичны.
В родительском классе есть конструктор:
public Object(Scanner sc){
this.POINT = sc.next();
this.name = sc.next();
this.price = sc.nextInt(); // Ругается на эту строку в коде
this.number = sc.nextInt();
}
А два дочерних содержат следующие:
public ChildObject1(Scanner sc) {
super(sc);
this.valueInt = sc.nextInt();
}
и, соответственно
public ChildObject2(Scanner sc) {
super(sc);
this.valueDouble = sc.nextDouble();
}
Я пытаюсь считать файл следующим образом:
Scanner sc = null;
try {
sc = new Scanner(new FileReader("src/file.txt"));
sc.useLocale(Locale.ENGLISH);
int i = 0;
Object[] object= new Object[6];
while (sc.hasNext()){
object[i] = new Object(sc);
i++;
}
} catch (FileNotFoundException e) {
System.err.println("Input file is not found");
} finally {
if(sc != null) {
sc.close();
}
}
И, собственно, сам файл:
Point1 Bla 2500 5
Point1 Bla 2500 3
Point2 Bla 2500 11 400
Point2 Bla 2500 13 200
Point3 Bla 2500 7 8,5
Point3 Bla 2500 6 5,2