How to read a string containing a '\' using opencsv?

后端 未结 3 1578
梦毁少年i
梦毁少年i 2020-12-11 02:41

When I\'m reading a csv-file using opencsv it doesn\'t work properly when encountering a \'\\\' at the end of a string. It makes the \" part of the string, instead of the \'

3条回答
  •  一个人的身影
    2020-12-11 02:52

    More cleaner and recommended solution is to use RFC4180Parser instead of default CSVParser:

    String csv = "come,csv,string";
    RFC4180Parser rfc4180Parser = new RFC4180ParserBuilder().build();
    CSVReader csvReader = new CSVReaderBuilder(new StringReader(csv)).withCSVParser(rfc4180Parser).build(); 
    

    Reference: https://sourceforge.net/p/opencsv/support-requests/50/

提交回复
热议问题