fel*_*hst -1 java csv supercsv
我正在尝试使用包含两个字段(制表符分隔)的超级CSV和未加引号的字符串来解析CSV文件.
occugroup_code occugroup_name
110000 Management Occupations
130000 Business and Financial Operations Occupations
150000 Computer and Mathematical Occupations
我很难弄清楚如何配置CsvPreference以便能够为每两个返回一个Map.有人遇到过这个问题吗?
请您下次尝试自己做任何事情或者更具体地描述您的问题.
例如:
I try the CsvPreference.xyz but it didn't work, because I get the exception abc
CsvPreference pref = new CsvPreference('\"', '\t', "\n");
Run Code Online (Sandbox Code Playgroud)
这是完整的示例(已测试):
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();
}
Run Code Online (Sandbox Code Playgroud)
输出:
110000 | 管理职业
130000 | 商业和金融业务职业
150000 | 计算机与数学职业
| 归档时间: |
|
| 查看次数: |
4065 次 |
| 最近记录: |