Failed to read double quote csv

I need a solution. The problem in the values ​​of the csv file is smoothed out using double quotes, so my code cannot read the full value of the product, its only reading is "Marlin-12", but the full name of the product 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

Using im code to read csv file -

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();
}
+4
source share
2 answers

The CSV format is apparently specified in RFC 4180 . According to the Ostermiller website , you will have to use the Excel style. Documented how to use it. You end up using ExcelCSVParser.

+2
source

CSV CSVParser. , pojo..

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

Source: https://habr.com/ru/post/1649261/


All Articles