输出到 CSV 时更改 java 中的分隔符
我在网上或我的书中找不到任何关于此的信息,而且这是一本大书! Java 有没有办法在输出到 CSV 文件时更改默认分隔符。我想将其从逗号更改为 \t?我想这样做是因为当我放入包含逗号的字符串时,它们会转到下一个单元格,这很痛苦。
任何帮助将是最伟大的!
詹姆斯
I can't find any info on this on the net or in my book and it's a big book! Is there a way in Java to change the default delimiter when out putting to CSV files. I want to change it from a comma to \t? I want to do this because when I'm putting in string that contain a comma they go to the next cell which is a pain.
Any help would be most greatful!
James
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您用什么来创建 CSV 文件?如果您只是使用基本的 Java 写入文件方法,您应该能够选择您想要的分隔符。如果您使用的是 openCSV 等第三方 API,应该有一个命令来设置分隔符。
What are you using to create CSV files? If you are just using the basic Java write-to-file method, you should be able to choose what you want for delimiter. If you are using a third party API like openCSV, there should be a command to set the delimiter.
CSV 绝不是一个标准,Java 也没有对其的标准支持。难怪你的大书没有谈到它。
我建议使用 OpenCSV 编写 CSV。 CSVWriter 的构造函数 有一个分隔符参数。
编辑:
您在一小时前刚刚提出的问题中得到了相同的答案: 写包含逗号的 CSV
CSV is in no way a standard, and Java has no standard support for it. No wonder your big book doesn't talk about it.
I'd suggest using OpenCSV to write CSV. The CSVWriter's constructor has a separator argument.
EDIT :
You had this same answer in the question you just asked one hour ago : Write to CSV that contains comma
虽然这是很晚的答案,但它可能会对某人有所帮助
ae:在 Java Servlet 中
注意:此代码未经测试,仅用于说明目的。
Though this is very late answer, It may help someone
a.e : In Java Servlet
N.B : This code is not tested,for illustration purposes only.