我有下面的代码块,它使用OpenCSV读取CSV文件并存储第7列。我面对的问题是我使用;
作为CSV文件的分隔符,但它也需要,
作为分隔符。我怎样才能避免这种情况?阅读分号csv
将CSV放入CSV文件是不可能的,因为我们从客户端获得不可编辑的文件。
CSVReader reader = null;
String[] nextCsvLine = new String[50];
String splitBy = ";";
int count = 0;
try {
StringReader sr = new StringReader(new String(in, offset, len));
reader = new CSVReader(sr);
while ((nextCsvLine = reader.readNext()) != null) {
for (String linewithsemicolon : nextCsvLine) {
log.debug("Line read : "+linewithsemicolon);
String[] b = linewithsemicolon.split(splitBy);
if (count==0){
count++;
continue;
}
else {
detailItems.add(b[7]);
log.debug("7th position: "+b[7]);
count++;
}
}
这是哪种语言?它看起来像Java。您需要用编程语言标记您的问题 - 请参阅您的问题下的“编辑”链接。 –
是的,它的JAVA遗憾忘记链接。 –
您发布的代码对逗号没有反应。请提供[mcve]。 – Thomas