WriteAll (ResultSet res, Boolean b) opencsv method adds double quotes around data

When I use this function to write to the csv file, all data is embedded in double quotes.

Is there a way to write to a csv file without double quotes?

CSVWriter writer = new CSVWriter(new FileWriter(table+".csv"), '\t'); writer.writeAll(rset, true); writer.close(); 

file contains data in the form

 "EMPNO" "ENAME" "JOB" "MGR" "HIREDATE" "SAL" "COMM" "DEPTNO" "TAG" "LOOKUP" "7369" "SMITH" "CLERK" "7902" "17-Dec-1980" "800" "2" "20" "E" "1" "7499" "ALLEN" "SALESMAN" "7698" "20-Feb-1981" "1600" "2" "30" "E" "2" "7521" "WARD" "SALESMAN" "7698" "22-Feb-1981" "1250" "2" "30" "E" "3" "7566" "JONES" "MANAGER" "7839" "02-Apr-1981" "2975" "2" "20" "E" "2" 
+4
source share
2 answers
 CSVWriter writer = new CSVWriter(new FileWriter(table+".csv"), '\t', CSVWriter.NO_QUOTE_CHARACTER); writer.writeAll(rset, true); writer.close(); 

Link: opencsv CSVWriter JavaDoc

+17
source

I would like to add to the previous answer (you do not have enough points to add comments) @ user591593 - when using the NO_QUOTE_CHARACTER constructor, you should avoid the values โ€‹โ€‹yourself. See StringEscapeUtils

Moreover, it is better to specify the correct encoding, such as UTF-8, instead of assuming that the system default is correct:

 CSVWriter writer = new CSVWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8"), '\t', CSVWriter.NO_QUOTE_CHARACTER); String s = "some fun \t string with \" double quotes and \n new lines"; writer.writeNext(StringEscapeUtils.escapeCsv(s)); 
0
source

All Articles