以下示例是來自csv文件的記錄,該記錄由逗號分隔符分隔但是,如果某個特定列具有像下面的逗號一樣的逗號,用csv文件中的雙引號「」顯示。從CSV文件讀取帶有在其本身中指定的分隔符的csv文件
例子:列1,列2,「列3」, - ,1G9937
當我嘗試使用我的Java代碼,它只是打印列,而不是列第三的位置讀取該文件, 3我如何處理這種情況?
String cvsSplitBy = ",";
try {
br = new BufferedReader(new FileReader(csvFile));
while ((line = br.readLine()) != null) {
// use comma as separator
String[] businessdirection = line.split(cvsSplitBy);
System.out.println("FuncVP = " + businessdirection[0] + " , VP=" + businessdirection[1] + " , VP=" + businessdirection[2]+ " , VP=" + businessdirection[3] + " , VP=" + businessdirection[4]+ " , VP=" + businessdirection[5]);
看起來像這可能是有幫助的:http://stackoverflow.com/questions/1757065/splitting-a-comma-separated-string-but-ignoring-commas-in-quotes –