I have a question about my split function inside the file reading function. Here is my code. I tried to use split to put these text in to array. But the problem is I have this error. java.lang.NumberFormatException: For input string: "Sug" at java.base/java.lang.NumberFormatException.forInputString
public static SLL<train> readFile() {
SLL<train> list = new SLL();
try {
FileReader fr = new FileReader("Train.dat");
BufferedReader br = new BufferedReader(fr);
String line = "";
while (true) {
line = br.readLine();
if (line == null) {
break;
}
String[] text = line.split(" | ");
String tcode = text[0];
String train_name = text[1];
int seat = Integer.parseInt(text[2]);
int booked = Integer.parseInt(text[3]);
double depart_time = Double.parseDouble(text[4]);
String depart_place = text[5];
train t = new train(tcode, train_name, seat, booked, depart_time, depart_place);
list.addLast(t);
}
br.close();
fr.close();
} catch (Exception e) {
e.printStackTrace();
}
return list;
"SUG" should be added into train name because I declared train_name as a string.I think this error only appears when declaring the wrong data type, "12" should be added into seat, "3" should be added into booked, and so on. Can you guys explained to me what happened to "SUG". Thanks a lot :(
