转义Apache commons-csv中#(双引号)的特殊含义

rbl8hiat  于 2022-12-06  发布在  Apache
关注(0)|答案(2)|浏览(129)

在.tsv文件中,由于“#”(如“#HELLO”),HELLO打印在双引号中。我希望在写入.tsv时删除双引号
电流输出-〉"#HELLO"
预期输出-〉#HELLO

try ( CSVPrinter printer = new CSVPrinter(new FileWriter("data.tsv"), CSVFormat.TDF))
{
   printer.printRecord("#HELLO");

}catch (IOException ex) {
    ex.printStackTrace();
}
14ifxucb

14ifxucb1#

您需要调整格式

CSVFormat.Builder.create(CSVFormat.TDF)
    .withQuoteMode(QuoteMode.MINIMAL)
    .build();
mpgws1up

mpgws1up2#

我改变了版本的CSVCommons到1.8和下面的代码是为我工作...

CSVPrinter printer = new CSVPrinter(new FileWriter("data.tsv"), CSVFormat.TDF.withHeader("#default1", "default2").withEscape('"').withQuoteMode(QuoteMode.NONE)

相关问题