[ 
https://issues.apache.org/jira/browse/CSV-120?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14025851#comment-14025851
 ] 

Gary Gregory commented on CSV-120:
----------------------------------

Sounds like a good idea. Done:

{noformat}
commit -m "<action issue="CSV-120" type="add" dev="ggregory" due-to="Sergei 
Lebedev">CSVFormat#withHeader doesn't work with CSVPrinter</action>" 
C:/vcs/svn/apache/commons/trunks-proper/csv/src/main/java/org/apache/commons/csv/CSVFormat.java
 
C:/vcs/svn/apache/commons/trunks-proper/csv/src/main/java/org/apache/commons/csv/CSVPrinter.java
 
C:/vcs/svn/apache/commons/trunks-proper/csv/src/test/java/org/apache/commons/csv/CSVPrinterTest.java
 C:/vcs/svn/apache/commons/trunks-proper/csv/src/changes/changes.xml
    Sending        
C:/vcs/svn/apache/commons/trunks-proper/csv/src/changes/changes.xml
    Sending        
C:/vcs/svn/apache/commons/trunks-proper/csv/src/main/java/org/apache/commons/csv/CSVFormat.java
    Sending        
C:/vcs/svn/apache/commons/trunks-proper/csv/src/main/java/org/apache/commons/csv/CSVPrinter.java
    Sending        
C:/vcs/svn/apache/commons/trunks-proper/csv/src/test/java/org/apache/commons/csv/CSVPrinterTest.java
    Transmitting file data ...
    Committed revision 1601517.
{noformat}

> CSVFormat#withHeader doesn't work with CSVPrinter
> -------------------------------------------------
>
>                 Key: CSV-120
>                 URL: https://issues.apache.org/jira/browse/CSV-120
>             Project: Commons CSV
>          Issue Type: Bug
>            Reporter: Sergei Lebedev
>            Priority: Minor
>             Fix For: 1.0
>
>
> 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