简体   繁体   中英

Parse CSV with quoted multiline string

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM