Skip to content

NamedCSVReader add header line number #66

Closed Answered by osiegmar
sbi1 asked this question in Q&A
Discussion options

You must be logged in to vote

As defined in section 2.3 of RFC 4180:

There maybe an optional header line appearing as the first line

In section 2.1.3 of current DRAFT RFC 4180-bis this is updated:

The first record in the file MAY be an optional header

followed by section 2.1.8:

[...] A comment line MAY appear in any line of the file (before or after an OPTIONAL header)

This is what the NamedCsvReader supports:

String csv = "# commented line\nheader\nbody\n";

NamedCsvReader.builder()
    .skipComments(true)
    .build(csv)
    .forEach(row -> System.out.println(row.getField("header")));

In order to skip non-RFC-compliant CSV data at the beginning you could use a BufferedReader:

BufferedReader br = new BufferedRe…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by osiegmar
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants