我在存储从.txt文件读取的数据时遇到问题,我试图根据行开头的键来存储数据。但由于某种原因,它只是按原样打印出文件。
以下是代码:
File file = new File(selectedFile.getAbsolutePath());
}
if (connectionTab.startsWith("Connection: ")) {
continue;
}
if (!sca.hasNext()) {
break;
}
String connection = sca.next();
if (!sca.hasNext()) {
continue;
}
String otherConnection = sca.next();
if (!sca.hasNextDouble()) {
continue;
}
double distance = sca.nextDouble();
TrainNetwork.newStation.addConnection(connection, otherConnection, distance);
System.out.println(connection + " " + otherConnection + " " + distance);
}
} catch (FileNotFoundException e) {
System.out.println("File not found");
}
答案 0 :(得分:1)
您使用第二个 :-
立即continue;
循环。删除它,
if(stationTab.startsWith("Station: ")) {