Commons CSV
  1. Commons CSV
  2. CSV-120

CSVFormat#withHeader doesn't work with CSVPrinter

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.0
    • Component/s: None
    • Labels:
      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.

        Activity

          People

          • Assignee:
            Unassigned
            Reporter:
            Sergei Lebedev
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development