opencsv的writeAll(ResultSet res,Boolean b)方法在数据周围添加双引号
当我使用此函数写入 csv 文件时,所有数据都嵌入在双引号中。
有没有办法在不使用双引号的情况下写入 csv 文件?
CSVWriter writer = new CSVWriter(new FileWriter(table+".csv"), '\t');
writer.writeAll(rset, true);
writer.close();
该文件包含以下形式的数据
"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"
When I use this function to write to a csv file all the data is embedded in double quotes.
Is there a way to write to csv file without the double quotes?
CSVWriter writer = new CSVWriter(new FileWriter(table+".csv"), '\t');
writer.writeAll(rset, true);
writer.close();
the 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"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
参考:opencsv CSVWriter JavaDoc
Reference: opencsv CSVWriter JavaDoc
我想添加 @user591593 之前的答案(没有足够的点来添加注释) - 在使用 NO_QUOTE_CHARACTER 构造函数时,您应该自己转义这些值。请参阅 StringEscapeUtils
更多最好指定一种正确的编码,例如 UTF-8,而不是假设系统默认编码是正确的:
I'd like to add to the previous answer (don't have enough points to just add to comments) by @user591593 - while using the NO_QUOTE_CHARACTER constructor, you should escape the values yourself. See StringEscapeUtils
More over, it's best to specify a proper encoding, such as UTF-8, instead of assuming that the system default is the correct one: