Artwar Artwar - 1 year ago 150
Java Question

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.

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?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download