Good morning Community:
I have an employee.dat file with the following content (the correlative numbering in the left margin is not part of the contents of the file):
When executing I get the exception: Exception in thread "main" java.lang.NumberFormatException: For input string: "r"
The error marks it in another method that makes the reading of the file and constructs the employee objects (Exactly in the line: double salary = Double.parseDouble (tokens [2]);
public static Employee readEmployee(Scanner in)
{
String line = in.nextLine();
String[] tokens = line.split("\ |");
String name = tokens[0];
String role = tokens[1];
double salary = Double.parseDouble(tokens[2]);
int year = Integer.parseInt(tokens[3]);
int month = Integer.parseInt(tokens[4]);
int day = Integer.parseInt(tokens[5]);
return new Employee(name, role, salary, year, month, day);
}
The main method from which I make the call is:
// recupera todos los registros en un nuevo array
try(Scanner in = new Scanner(new FileInputStream("employee.dat"), "UTF-8"))
{
Employee[] newStaff = Employee.readData(in);
// print los nuevos registro de empleados
for(Employee e : newStaff)
{
System.out.println(e);
}
}
I hope your kind help with this exception.
Thank you.