Search code examples
javacsvapache-commons-csv

Apache commons CSV-parse record with new line chars


How to parse a CSV record that contains new line characters within quotes as below

1, Test, "testing
testing
testing"

I'm currently using Apache CSV lib

CSVFormat.DEFAULT.withFirstRecordAsHeader().parse(new FileReader(file));

Solution

  • Figured it out. This happens because of the spaces around the delimiter. I works perfectly when the spaces are removed.

    1,<SPACE>Test,<SPACE>"testing
    testing
    testing"