Sergei Lebedev created CSV-120:
----------------------------------

             Summary: 'withHeader' doesn't work for 'CSVPrinter'
                 Key: CSV-120
                 URL: https://issues.apache.org/jira/browse/CSV-120
             Project: Commons CSV
          Issue Type: Bug
            Reporter: Sergei Lebedev
            Priority: Minor


In the current version 
[CSVFormat#withHeader|https://commons.apache.org/proper/commons-csv/apidocs/org/apache/commons/csv/CSVFormat.html#withHeader(java.lang.String...)]
 is only used by CSVParser. It would be nice if CSVPrinter also supported it. 
Ideally, the following line of code

{code:java}
CSVPrinter csvPrinter
  = CSVFormat.TDF
    .withHeader("x")
    .print(Files.newBufferedWriter(Paths.get("data.csv")));
csvPrinter.printRecord(42);
csvPrinter.close();
{code}

should produce

{code}
x
42
{code}

If you're alright with the idea of automatically inserting headers, I can 
attach a patch.



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to