2

I am using apache-common-csv to import data from the CSV file and I would like to skip headers in the first line. What is important, the file sometimes can contain headers but sometimes not. I have an implementation like below but the result not satisfying me, because when the file is without headers the first line is cutting.

CSVFormat.DEFAULT
        .withDelimiter(';')
        .withHeader(HEADERS)
        .withSkipHeaderRecord()
        .parse(InputStreamReadersource.inputStream)
db9
  • 123
  • 1
  • 10

1 Answers1

0

I think this could help you.

CSVFormat.RFC4180
         .withFirstRecordAsHeader()
         .withDelimiter(';').parse(InputStreamReadersource.inputStream);

Here is the reference on Commons CSV user guide https://commons.apache.org/proper/commons-csv/user-guide.html

John Kangari
  • 31
  • 3
  • 10