我有一个定义如下的阅读器:
CSVReader csvReader =new CSVReader(new InputStreamReader(inputStream), ',', '\'');
StringBuilder stringBuilder = new StringBuilder();
String[] line;
if (SPECIAL_CHARS == null || SPECIAL_CHARS.length == 0) {
return inputStream;
}
String[] stringArrSpecialChars = new String(SPECIAL_CHARS).split("");
while ((line = csvReader.readNext()) != null) {
//do somthing
}
它如何引发此错误:
java.io.IOException: Unterminated quoted field at end of CSV line. Beginning of lost text: [D'Olra
当遇到带有:D'Olra的CSV单元格
有什么建议吗?
答案 0 :(得分:1)
通过将第一行替换为
来解决char charThatWillNotAppearInText = 127;
CSVReader csvReader = new CSVReader(new InputStreamReader(inputStream), ',', charThatWillNotAppearInText);
这是一种变通方法,它假定127的char永远不会成为输入CSV文件的一部分,并禁用了'quotechar'选项。