I am using au.com.bytecode.opencsv.CSVReader to read A csv file and print all the records one by one. The code is behaving strange. It's printing a group of lines together as a single line. Then again it's printing next set of lines correctly.
Please download the CSV file from the link above. My code is considering the first line as - from first non-header line to the line just above the line which has below content:
12/4/13: Changed AO to Chief Financial officer.","07/18/2016",
Also, my first data line contains \" in one of the fields. You can do Cntrl +F with \" to find it. If I remove \ from the field , it works fine. Now my question is what logic CSVReader is using to end the first line as specified above? Why is it taking the end of line just before the line which has below content:
12/4/13: Changed AO to Chief Financial officer.","07/18/2016",
It's taking a new line from '12/4/13.........' . Also, the individual lines below that are being taken as separate lines perfectly .
Code for your reference :
csvReader reader = new CSVReader(new FileReader(fileNameWithLocation), ',', '"', 1);
ColumnPositionMappingStrategy<DomainObj> mappingStrategy =
new ColumnPositionMappingStrategy<DomainObj>();
mappingStrategy.setType(DomainObj.class);
String[] nextLine;
while ((nextLine = reader.readNext()) != null)
{
if (nextLine != null)
log.debug("Next line : " + Arrays.toString(nextLine));
}