我有一个CSV文件(如果有影响,其中的信息是用西里尔字母编写的)。CSV类的编写方式是读取每一行并在逗号上进行拆分:
String[] row = csvLine.split(",");
在csv中,我有以下格式的行:
ааа,бб, рр, ррр рр тт.
我该如何强制CSV只在第一个逗号处分割? 附注:我已经尝试使用双逗号和斜杠来转义逗号,但目前还没有成功。 编辑: 以下是整个CSVreader类的代码:
public class CSVReader {
InputStream inputStream;
public CSVReader(InputStream is) {
this.inputStream = is;
}
public List<String[]> read() {
List<String[]> resultList = new ArrayList<String[]>();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
try {
String csvLine;
while((csvLine = reader.readLine()) != null) {
String[] row = csvLine.split(",");
resultList.add(row);
}
} catch(IOException ex) {
throw new RuntimeException("Error in reading CSV file:" + ex);
} finally {
try{
inputStream.close();
} catch(IOException e) {
throw new RuntimeException("Error while closing input stream: " + e);
}
}
return resultList;
}
我需要的是从CSV中提取上述摘录,仅在第一个逗号处进行拆分,并解析并显示其后遇到的内容。