java - How to read a string containing a '\' using opencsv? -
java - How to read a string containing a '\' using opencsv? -
when i'm reading csv-file using opencsv doesn't work when encountering '\' @ end of string. makes " part of string, instead of '\' want to. guess there must method add together '\' escape '\'-character instead? without having manually edit csv-file. have searched not found anything.
to clarify problem, looks this:
csv-file
"a", "b", "c", "d" "value 1", "value 2", "value 3", "value 4" "value 5", "value 6\", "value 7", "value 8"
my code looks (not really, shows problem):
string infile = "in.csv"; csvreader reader = new csvreader(new filereader(infile)); string[] line; while ((line = reader.readnext()) != null) { (int = 0; < line.length(); i++) { system.out.println(i + " " + line[i]); } }
i want parse string[] 4 elements each, each row, lastly row parses 2 elements, shown in output below.
1 2 b 3 c 4 d 1 value 1 2 value 2 3 value 3 4 value 4 1 value 5 2 value 6",value 7,value 8
i have tried alter reader to:
csvreader reader = new csvreader(new inputstreamreader(new fileinputstream(infile), "utf-8"));
but without luck.
maybe alter escape character in constructor of reader?
csvreader(new inputstreamreader(new fileinputstream(infile), ',', '"', '|')
this assuming |
not used in cvs file
more info here: http://opencsv.sourceforge.net/apidocs/au/com/bytecode/opencsv/csvreader.html
java opencsv
Comments
Post a Comment