Search code examples
javacsvapache-commons-csv

Escape special meaning of # (double quote) in Apache commons-csv


HELLO printing in a double quote in .tsv file because of '#' like "#HELLO". I want to remove the double quotes when it writes to .tsv

current output -> "#HELLO"

expected output -> #HELLO

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

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

Solution

  • I changed the version of CSVCommons to 1.8 and below code is working for me...

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