到目前为止我所理解的是,它将逐行读取文件,同时,它将分割记录并将其保存在字段数组中,之后我无法理解它将在记录列表中添加什么...... . 因为它直接将字段数组添加到列表中。
String fileName = "C:\\data.csv"
public static Collection<String[]> getTestData(fileName) throws IOException {
List<String[]> records = new ArrayList<String[]>();
String record;
BufferedReader file = new BufferedReader(new FileReader(fileName));
while ((record=file.readLine())!=null) {
String fields[] = record.split(",");
records.add(fields);
}
file.close();
return records;
}
CSV 文件
160,45,17.6,减持 168,70,24.8,正常 181,89,27.2,增持 178,100,31.6,肥胖