我是Java的新手,我必须解析一个.csv文件。该文件在每一行中包含学生的ID,他们通过的科目ID和他们通过的科目成绩。例如:
Student ID,Subject ID,Grade
1,A1-102,7
1,A1-103,6
1,A1-104,5
1,A1-108,9
2,A1-101,5
2,A1-105,7
我需要计算一个学生通过的类似于SQL's GROUP BYEg的课程的数量:SELECT count(*) FROM STUDENTS GROUP BY Student_ID;假设csv文件已打开并可以读取,是否可以为一个学生对多个条目进行分组?
我的代码:
csvFile = "C:\\Myfile.csv";
try {
br = new BufferedReader(new FileReader(csvFile));
while ((line = br.readLine()) != null) {
// what do i need to do here?
}
} catch (FileNotFoundException e) {
System.out.println("File not found\n");
} catch (IOException e) {
System.out.println("An I/O exception has occured\n");
} finally {
if (br != null)
try {
br.close();
} catch (IOException e) {
System.out.println("File is already closed");
}
}
有什么想法吗?
天涯尽头无女友
相关分类