所以我正在开展一个学校项目,我们必须从文本文件中导入一个项目列表。以下是文件格式的示例:
我一直在使用这部分代码获得输入不匹配异常(我已经从for循环变为while循环)。我要导入的3件事是名称,等级和等级,这是我到目前为止所做的:
File myFile = new File("input.txt");
if (!myFile.exists()) {
System.out.println("Can't Find File");
System.exit(0);
}
Scanner reader = new Scanner(myFile);
int i = 0;
while (reader.hasNext()) {
names[i] = reader.nextLine();
grade[i] = reader.nextInt();
rank[i] = reader.nextInt();
i++;
}
reader.close();
如何获取正确数组的信息?
P.S我不能使用ArrayList
s(即使我希望我能)