Reputation: 11425
I am using opencsv to read a csv file. Some time the csv files have single or double quotes in them. How do i read them without changing the data in the csv file itself.
Right now if I replace a single quote with two single quotes it works fine, same with double quotes, replace a single one with two and it works. But I do not want to touch the source file.
The code to access is as following
CSVReader reader = new CSVReader(new InputStreamReader(new FileInputStream(file), "UTF-8"), delimiter,'\"',0);
data = a1;b1;c1;hello"world;d1;e1
a2;b3;c2;hello"world;d2;e2
; is the delimiter
The result of this is the next row which also contains a double quote is skipped, All odd numbered rows are inserted where as the even numbered rows are skipped
Thanks in advance
Upvotes: 1
Views: 3322
Reputation: 940
Solution 1 : One possible thing you could do, Assuming you don't want double course/single courses in your output file.
Solution 2: If you want to keep all the special character then put a "\" backlash before special characters. then read it.
Upvotes: 1