我有下面的代碼塊,它使用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