Uploaded image for project: 'Commons CSV'
  1. Commons CSV
  2. CSV-120

CSVFormat#withHeader doesn't work with CSVPrinter

VotersWatch issueWatchersLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • 1.0
    • None
    • None

    Description

      In the current version CSVFormat#withHeader is only used by CSVParser. It would be nice if CSVPrinter also supported it. Ideally, the following line of code

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

      should produce

      x
      42
      

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

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            Unassigned Unassigned
            lebedev Sergei Lebedev
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment