//从文件中获取数据,并转化为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
CSV文件解析与映射
最新推荐文章于 2023-08-23 17:06:52 发布
本文介绍了如何将CSV文件的内容转换成Map结构,包括解析CSV文件的步骤、数据映射的技巧以及使用相关库进行高效处理的方法。
696

被折叠的 条评论
为什么被折叠?



