我已经从一个文本文件扫描了各行,现在需要将行分隔为四个不同的字符串,然后将它们添加到数组中。任何帮助我在这里做错了吗?试图扫描已经扫描的文件中的一行字符串
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();
}
您应该指定正在发生的事情。 –