//从文件中获取数据,并转化为list(list里面放的是map(map中放的是一一对应的数据))
ArrayList<Map<String, String>> datas = new ArrayList<>();
try {
FileReader localFile = new FileReader(filePath + "\\" + "shujuku.csv");//文件路径根据不同的数据源进行修改
BufferedReader reader = new BufferedReader(localFile);
//第一行 表头
String firstLine = reader.readLine();
String[] titleItems = firstLine.split(",");
String line = null;
//读取每一行,拼成map
while ((line=reader.readLine()) != null){
String[] items = line.split(",");
HashMap<String, String> map = new HashMap<>();
for (int i = 0; i < titleItems.length; i++) {
map.put(titleItems[i],items[i]);
}
datas.add(map);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
csv文件导入为map
最新推荐文章于 2022-11-20 12:27:54 发布