1

I need to parse CSV file that may contain quoted multiline string like below:

ID;Name;Password;address; phoneNum      
1; "userName"; "userPassword"; "user \n 
    address"; 1234523423

I looked through Commons CSV library's functionality which seems to satisfy the majority of requirements, but it doesn't seem to have an option to read next line in case quotes aren't closed.

Obviously, if there is a need to use a single quote, it should be screened with an extra pair of double quotes.

3
  • 1
    IMHO that should never even be an option. That's how CSV is supposed to be parsed. Commented Feb 21, 2017 at 10:28
  • 2
    The tests seem to suggest that this works out of the box (as it should). Commented Feb 21, 2017 at 10:31
  • For those having the general issue, the answers to the question Importing multiline cells from csv file into excel might help. For instance, LibreOffice can import the file and save it "correctly" to xls format. Commented Jul 19, 2020 at 8:57

1 Answer 1

4

It should work just fine unless there's some bug in the library or misconfiguration. However it might be the case that your password has an unescaped/unclosed quoted field and this not being written properly.

If that's the situation, give univocity-parsers a try as it has many different options to handle unescaped/unclosed quotes properly. It is also 4 times faster than Commons CSV.

Disclosure: I'm the author of this library.

Sign up to request clarification or add additional context in comments.

1 Comment

Got the 1Gb csv file both with unescaped quotes and multi-line values. Much thanks to @jeronimo-backes for his univocity-parsers. Small memory footprint, flexible settings, friendly support.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.