java opencsv,Java OpenCSV写入结果集 - 行/行的结束

"在尝试使用OpenCSV库将SQL查询结果导出为逗号分隔的CSV文件时,遇到了一个问题:生成的CSV文件在Notepad中显示为单行,没有正确地用换行符分隔行。尽管文件在Excel中导入时格式正确,但目标是使其在纯文本编辑器中也易于阅读。解决方案是使用SystemProperties的"line.separator"代替" "作为行分隔符,确保在所有操作系统上都能正确创建新行。"
摘要由CSDN通过智能技术生成

I'm trying to export a SQL resultset to a comma delimited csv file using opencsv library. However when I pass the result set to the writeAll function, all works well except for the file that it generates does not separates the rows with a new line and creates a nearly un readable file when opened in notepad. Albeit the file that is created is valid and delimits well when imported into excel. However, I need the file this code generates to be readable when opened with a simple text editor. Any suggestions?

My CSV file handle looks like this:

CSVWriter wt = new CSVWriter(new FileWriter("file"), ',',

CSVWriter.NO_QUOTE_CHARACTER, CSVWriter.NO_ESCAPE_CHARACTER, "\n");

解决方案

Use the System Properties: line separator instead of "\n" (on Windows, "\r\n" is end of line),

CSVWriter wt = new CSVWriter(new FileWriter("file"), ',',

CSVWriter.NO_QUOTE_CHARACTER,

CSVWriter.NO_ESCAPE_CHARACTER,

System.getProperty("line.separator"));

From the System Properties link above,

"line.seperator"

Sequence used by operating system to separate lines in text files

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值