我正在使用 org.apache.commons-csv 1.4,本周我在我们的一个 junit 测试中发现了这种奇怪的行为:
CSVReader reader = null;
List<String[]> linesCsv = new ArrayList<>();
FileInputStream fileStream = null;
InputStreamReader inputStreamReader = null;
try {
fileStream = new FileInputStream(file);
inputStreamReader = new InputStreamReader(fileStream, "ISO-8859-1");
reader = new CSVReader(inputStreamReader, ',', '"', 0);
String[] record = null;
while ((record = reader.readNext()) != null) {
linesCsv.add(record);
}
} catch (Exception e) {
logger.error("Error in ", e);
} finally {
if (inputStreamReader != null) {
inputStreamReader.close();
}
if (fileStream != null) {
fileStream.close();
}
if (reader != null) {
reader.close();
}
}
*错误案例
输入 .csv
DAR_123451 ,"XXXXX Hello World "Hello World XXX "
DAR_123452 ,"XXXXX Hello World "Hello World XXX "
爪哇KO:
[0.0] DAR_123451
[0.1] XXXXX Hello World "Hello World XXX\nDAR_123456 ,XXXXX Hello World "Hello World XXX
*正确案例
输入 .csv
DAR_123451 ,"XXXXX Hello World "Hello World" XXX "
DAR_123452 ,"XXXXX Hello World "Hello World" XXX "
爪哇好:
[0.0] DAR_123451 [0.1] XXXXX Hello World “Hello World” XXX
[1.0] DAR_123452 [1.1] XXXXX Hello World “Hello World” XXX
我无法将 commons csv 库设置为正常工作,这似乎是一个错误,我们如何才能正确读取字符串中带有单引号的字符串?