使用apachecommons时删除csv文件开头的双引号

k10s72fa  于 2021-06-30  发布在  Java
关注(0)|答案(0)|浏览(391)

我正在读取一个csv文件,文件之间有空行,并使用apachecommons库将空行写入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文件并写入该文件后,会在记录的开头添加双引号,其中的空值如下:

"", ,"14,000", 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();

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题