扫描输入文件时输入不匹配

时间:2014-01-29 05:13:28

标签: java

所以我正在开展一个学校项目,我们必须从文本文件中导入一个项目列表。以下是文件格式的示例:

enter image description here

我一直在使用这部分代码获得输入不匹配异常(我已经从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(即使我希望我能)

0 个答案:

没有答案