Search code examples
javacsvimportsupercsv

Skip Optional Header in CSV file with SuperCSV


I have a system where users can import data through csv files. The file is parsed to POJOs using SuperCSV.

I want to be able to manage these files with or without the header row.

CsvBeanReader.getHeader(true) will extract the first row, but if it is not a header then that row won't be parsed by the BeanReader.

Is there an easy way of detecting the header without losing the first line of data?


Solution

  • I found a solution.

    By wrapping the provided Reader using a BufferedReader I could mark the beginning, read the first line, and then do reader.reset() if it's not the header.