Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Skip first line using Open CSV reader

Tags:

Here is the line i am using currently

File booleanTopicFile; // booleanTopicFile is csv file uploaded from form CSVReader csvReader = new CSVReader(new InputStreamReader(new FileInputStream(booleanTopicFile), "UTF-8")); 

Want to skip the first line of the csv which contains headings. I dont want to use any separator as except the default one comma(,) which is already available in default constructor. In parameterized constructor there is a option to skip no. of lines but how to deal with the 2nd and 3rd param of the constructor.

CSVReader csvReader = new CSVReader(new InputStreamReader(Reader reader, char c, char c1, int index); 

-- Thanks

like image 850
Sangram Anand Avatar asked Nov 27 '12 07:11

Sangram Anand


People also ask

How to skip first row in CSV?

The next () method, when we call it, automatically discards the first row from the csv reader object and the rest of the data we can use as we need.


1 Answers

This constructor of CSVReader class will skip 1st line of the csv while reading the file.

CSVReader reader = new CSVReader(new FileReader(file), ',', '\'', 1); 
like image 80
Abhijeet Doshi Avatar answered Nov 07 '22 12:11

Abhijeet Doshi