我已經從一個文本文件掃描了各行,現在需要將行分隔爲四個不同的字符串,然後將它們添加到數組中。任何幫助我在這裏做錯了嗎?試圖掃描已經掃描的文件中的一行字符串
public void method()throws FileNotFoundException{
FileDialog fileBox = new FileDialog(mainWindow,"Open", FileDialog.LOAD);
fileBox.setVisible(true);
fileBox.setDirectory(".");
String dataFile = fileBox.getFile();
Scanner scanner = new Scanner(new File(dataFile));
while(scanner.hasNext())
{
String lineOfInput = scanner.nextLine();
if (lineOfInput.startsWith("/") || lineOfInput.startsWith("[") && lineOfInput !=null)
scanner.nextLine();
else
{
String newLineOfInput = lineOfInput.trim();
System.out.println(newLineOfInput);
Scanner newScanner = new Scanner(newLineOfInput);
while(newScanner.hasNext())
{
String group = scanner.next();
String vehID = scanner.next();
String regNo = scanner.next();
String make = scanner.next();
storeVehicle(new Vehicle(group, vehID, regNo,make));
newScanner.close();
}
}
scanner.close();
}
您應該指定正在發生的事情。 –