djennings93
djennings93

Reputation: 37

opencsv CSV Reader - Read from specific row onwards.

I've been searching this everywhere, I'm probably just being thick but is there a way to read a csv file from a particular row onwards? I have a csv file but want to read the data from the 14th row onwards. Below is my csv reader.

  CSVReader reader=new CSVReader(new FileReader(filename1));
  String [] value ;

  while((value=reader.readNext())!=null){

The data inside the csv is something like this

    1   djennings93
    2   27/02/2014
    3   13:31
    ...
    14  26/02/14 14:25:00, www.google.co.uk, 50, Google

I'd like to ignore the data from lines 1-13

Upvotes: 3

Views: 6529

Answers (2)

Kirill Feoktistov
Kirill Feoktistov

Reputation: 1448

Boris's answer still works but deprecated. It is recommended to use builder class:

CSVReader reader = new CSVReaderBuilder(new FileReader("yourfile.csv"))
        .withSkipLines(13)
        .withCSVParser(new CSVParserBuilder().withSeparator('\t').withEscapeChar('\'').build())
        .build();

Upvotes: 3

Boris
Boris

Reputation: 24453

You can skip the first 13 lines by doing:

CSVReader reader = new CSVReader(new FileReader("yourfile.csv"), '\t', '\'', 13);

Have a look here. (question Can I use my own separators and quote characters?)

This will result in reading the data from the 14th line onward.

Upvotes: 4

Related Questions