我正在尝试使用包含两个字段(制表符分隔)的Super CSV解析CSV文件,并使用不带引号的字符串。
occugroup_code occugroup_name 110000 Management Occupations 130000 Business and Financial Operations Occupations 150000 Computer and Mathematical Occupations
我很难弄清楚如何配置CsvPreference以便能够为每两个返回一个Map。有人遇到过这个问题吗?
答案 0 :(得分:8)
请您下次尝试自己做任何事情或者更具体地描述您的问题
例如:
I try the CsvPreference.xyz but it didn't work, because I get the exception abc
CsvPreference pref = new CsvPreference('\"', '\t', "\n");
以下是完整示例(已测试):
InputStream inputStream = this.getClassLoader().getResourceAsStream("example.csv");
CsvPreference pref = new CsvPreference('\"', '\t', "\n");
ICsvMapReader reader = new CsvMapReader(new InputStreamReader(inputStream), pref);
List<Map<String, String>> list = new ArrayList<Map<String, String>>();
Map<String, String> result;
while ((result = reader.read(new String[]{"code", "name"})) != null) {
list.add(result);
}
for (Map<String, String> elem : list) {
System.out.print(elem.get("code")+" | ");
System.out.print(elem.get("name"));
System.out.println();
}
输出:
110000 |管理职业
130000 |商业和金融业务职业
150000 |计算机和数学职业