使用apache commons时去掉csv文件开头的双引号

问题描述

我正在读取一个中间有空行的 csv 文件,并使用 apache commons 库将空行写入 csv 文件我有如下带有列名的 csv 文件

Username  Password  Amount  Timestamp  
AA,yes,"12,100",11:30  
AB,No,"13,900",12:30  
--empty row--,"14,000",10:40

读取 csv 文件并写入文件后,将双引号添加到记录的开头,其中的空值如下:

"",10:40

请告诉我如何打印不带双引号的记录。我的代码如下。

String CSV_File_Path = "Sample.csv";
CSVConversion records = new CSVConversion(CSV_File_Path);
List<CSVRecord> csvRecords = records.getRecords();
BufferedWriter writer =
    Files.newBufferedWriter(Paths.get("Sample2.csv"));

CSVPrinter csvPrinter =
    new CSVPrinter(
        writer,CSVFormat.DEFAULT.withHeader(
            "Username","Password","Amount","Timestamp"));
            
csvPrinter.printRecords(csvRecords);
csvPrinter.flush();
csvPrinter.close();

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)