文件到集合ArrayLsit改进版本

package com.czie.iot1913.lps.IO.BufferStream;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;

/**
* FileName: TxtToArrayList01
* Author: lps
* Date: 2022/3/26 18:34
* Sign:刘品水 Q:1944900433
*/
public class TxtToArrayList01 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new FileReader("F:\\JavaCode\\array.txt"));
ArrayList<Students> array = new ArrayList<>();
String line;
while ((line= br.readLine())!=null) {
String[] strArray = line.split(",");
Students s1 = new Students();
s1.setNumber(strArray[0]);
s1.setName(strArray[1]);
s1.setAge(Integer.parseInt(strArray[2]));
s1.setLiveofplace(strArray[3]);
array.add(s1);
}
br.close();
for (Students s:array){
System.out.println(s);
}

}
}

 

posted @ 2022-03-26 18:49  刘品水  阅读(16)  评论(0编辑  收藏  举报