引用符で囲まれていない文字列を持つ 2 つのフィールド (タブ区切り) を含む Super CSV を使用して CSV ファイルを解析しようとしています。
occugroup_code occugroup_name 110000 管理職 130000 ビジネスおよび金融業務の職業 150000 コンピューターと数学の職業
CsvPreference を構成して、2 つごとにマップを返すことができるようにする方法を理解するのに苦労しています。誰でもこの問題に遭遇しましたか?
次回は自分で何かをしてみるか、問題をより具体的に説明してください。
例えば:
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 | コンピュータと数学の職業