Java读取txt文件中的数据到数组里

已经定义了一个Student类,包含学号、姓名、班级等数组
现在编写了一个txt文件,含有学号、姓名、班级的数据,用了逗号分隔每行数据的三种信息
需要读取这个txt文件里的三种信息到我的Student里面

对文件进行按行读取,对每一行进行逗号分隔,然后依次赋值给Student对象中。

先使用流读取txt文件,随后将读取出来的内容进行按逗号分割
最后将分割好的内容放在对象中即可:


String fileName = "/Users/pankaj/source.txt";
File file = new File(fileName);
FileReader fr = new FileReader(file);
BufferedReader br = new BufferedReader(fr);
String line;
while((line = br.readLine()) != null){
    //process the line
    System.out.println(line);
}

用scanner去读,然后对每一行进行分割,把分割后的串按需求转化为int等,然后新建Student对象存入