opencsv in java ignores backslash in a field value

In addition to @JMM 's answer, you have to use this created CSVParser in the constructor of the CSVReader. The only available constructor is:

public CSVReader(Reader reader, int line, CSVParser csvParser)

You can set the line to 0 so that it will not skip anything


I had the same problem and couldn't find another character I could guarantee wouldn't show up in my csv file. According to a post on sourceforge though, you can use the explicit constructor with a '\0' to indicate that you don't want any escape character.

http://sourceforge.net/tracker/?func=detail&aid=2983890&group_id=148905&atid=773542

CSVParser parser = new CSVParser(CSVParser.DEFAULT_SEPARATOR, CSVParser.DEFAULT_QUOTE_CHARACTER, '\0', CSVParser.DEFAULT_STRICT_QUOTES);

I did a bit of cursory testing, and this seems to work just fine, at least backslashes certainly make it through.


CSVReader also has a parser builder via which you can set the escape character to use. If you use that and set the escape character to something you don't use you will get the backslash character in your input.

Tags:

Java

Opencsv