eshwar chettri
eshwar chettri

Reputation: 310

unable to read csv with double quotes

I need a solution.. The problem is in csv file product values are saperated with double quotes so my code is unable to read full product value its only reading "Marlin - 12" but full product name is "Marlin - 12"" - Custom".

PRODUCT_ID,CATEGORY,PRODUCT, MIN_STOCK_LEVEL
23,         cat1,  "Marlin - 12"" - Custom",2
24,         cat1,  "Marlin - 12"" – Custom1",3
25,         cat2,  "Marlin - 12"" – Custom2",3
26,         cat3,  "Marlin - 12"" – Custom3",2
27,         cat4,  "Marlin - 12"" - Custom",2
28,         cat5,  "Marlin - 12"" - Custom",2

Code im using for reading csv file is

import com.Ostermiller.util.CSVParser

...

else if ( fileName.contains(".csv")) {
    FileInputStream fis = new FileInputStream(fileName);
    CSVParser csvp = new CSVParser(fis);
    String[][] values = csvp.getAllValues();
    tempClientProductCol = new ClientProductCol();
}

Upvotes: 4

Views: 252

Answers (2)

spa
spa

Reputation: 5185

The CSV format seems to be the one specified in RFC 4180. According to the Ostermiller site, you would have to use the Excel style. It is documented how to use it there. You would end up using ExcelCSVParser.

Upvotes: 2

Murugan Deva
Murugan Deva

Reputation: 62

This is not problem in CSV File or CSVParser..It happend when you set the value to your pojo.. The Working code here

FileInputStream fis = new FileInputStream("path.csv");
CSVParser csvp = new CSVParser(fis);
String[][] values = csvp.getAllValues();    
System.out.println(values[1][2]);

Upvotes: -1

Related Questions