I have a CSV in the below format.
id,name,address,city
ABC,"DE""F",HIJ,"KLM""N"
OPQ,RST,"U""V","WXYZ"""
I am using OpenCSV to read the file. But City is reading KLM"N along with next line.
Eg: City is getting read like
KLM"N
OPQ,RST,U etc.
But OPQ should be id of the next record. I tried using withQuoteChar('"') but it did not work. Is there any other way to resolve this?
I tried the below code.
csvReader = new CSVReader(new InputStreamReader(inputStream));
String[] record = csvReader.readNext();
while ((record = csvReader.readNext()) != null) {
MyEntity entity = new MyEntity();
entity.setID(record[0]);
entity.setName(record[1]);
entity.setAddress(record[2]);
entity.setCity(record[3]);
}
Also tried the below snippet. try (CSVReader csvReader = new CSVReaderBuilder(new InputStreamReader(inputStream)) .withCSVParser(new CSVParserBuilder().withQuoteChar('"').build().build()){}