Min*_*sha 2 java-8 apache-commons-csv
我正在使用 apache commons CSV 解析器将 CSV 转换为地图。在地图中,我无法通过 intellij 调试器读取某些值。如果我手动输入map.get(“key”),则该值为空。但是,如果我从地图上复制粘贴密钥,我就会获取数据。无法理解出了什么问题。任何指示都会有所帮助。谢谢
这是我的 CSV 解析器代码:
private CSVParser parseCSV(InputStream inputStream) {
System.out.println("What is the encoding "+ new InputStreamReader(inputStream).getEncoding());
try {
return new CSVParser(new InputStreamReader(inputStream), CSVFormat.DEFAULT
.withFirstRecordAsHeader()
.withIgnoreHeaderCase()
.withSkipHeaderRecord()
.withTrim());
} catch (IOException e) {
throw new IPRSException(e);
}
}
Run Code Online (Sandbox Code Playgroud)
字符串中有一个奇怪的字符(参考:阅读 UTF-8 - BOM 标记)。以下语法有助于解决该问题
header = header("\uFEFF", "");
Run Code Online (Sandbox Code Playgroud)