public static void findInfo(String filePath) throws IOException {
//把之前存入到数据的文件,读取到集合中来。
ArrayList
readData(list,filePath);
//遍历集合
for(int i=0;i Student stu = list.get(i); System.out.println(stu.getId()+" "+stu.getName()+" "+stu.getAddress()); } } private static void readData(ArrayList FileReader fr = new FileReader(filePath); BufferedReader br = new BufferedReader(fr); //读物文件里面的信息 String line = null; while((line=br.readLine())!=null) { String[] str = line.split(","); //获取的数据封装成对象 //stu.getId()+","+stu.getName()+","+stu.getAge() Student stu = new Student(); stu.setId(str[0]); stu.setName(str[1]); stu.setAge(Integer.valueOf(str[2])); //将对象放到集合中区 list.add(stu); } } //输入学生的信息 public static void addInfo(String filePath) throws IOException{ ArrayList Scanner sc = new Scanner(System.in); //将输入的信息存放到集合里面去 for(int i=1;i<=3;i++) { System.out.println("请输入第"+i+"个学生的id"); String id = sc.next(); System.out.println("请输入第"+i+"个学生的name"); String name = sc.next(); System.out.println("请输入第"+i+"个学生的age"); int age = sc.nextInt(); Student stu = new Student(); stu.setId(id); stu.setAge(age); stu.setName(name); list.add(stu); } //将集合里面的信息写到文件里面去 writeDate(list,filePath); }