我正在研究一个程序,该程序将读取包含名称和后面的一些数字的文本文件。每次我试图找到它会给我索引超出范围错误!文本包含学生姓名,然后是姓名和每个数字之间的逗号。
public class GradingQuizes
{
final static String inResponses = "responses.txt";
final static String inKey = "key.txt";
public static void main(String[] args) throws IOException
{
Scanner responses;
Scanner answerKey;
File resp = new File(inResponses);
responses = new Scanner(resp);
File xkey = new File(inKey);
answerKey = new Scanner(xkey);
String line = " ";
ArrayList<Student> myClass = new ArrayList<Student>();
while (responses.hasNextLine())
{
int firstComma = line.indexOf(",");
String studentName = line.substring(0, firstComma);
System.out.println(studentName);
}
}
}