private static void readAllStudent(){
try {
//读取所有学生信息
private static void readAllStudent(){
try {
String line;
//读取文件
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(studentPath)));
//按行读取 判断改行是否为空
while((line = br.readLine()) != null) {
//学生信息属性 以 一个空格分割
String[] data = line.split(" ");
//将属性 放到对象中
Student student = new Student(data[0],data[1],data[2],data[3],Integer.parseInt(data[4]),data[5]);
//将对象添加到list
students.add(student);
}
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
从文件流中逐行读取到学生信息
使用缓冲流从文件读取学生信息,封装为学生对象,添加到集合里