BufferedReader to skip first line

Code picture Code · Apr 23, 2014 · Viewed 64.7k times · Source

I am using the following bufferedreader to read the lines of a file,

BufferedReader reader = new BufferedReader(new FileReader(somepath));
while ((line1 = reader.readLine()) != null) 
{
    //some code
}

Now, I want to skip reading the first line of the file and I don't want to use a counter line int lineno to keep a count of the lines.

How to do this?

Answer

Ruchira Gayan Ranaweera picture Ruchira Gayan Ranaweera · Apr 23, 2014

You can try this

 BufferedReader reader = new BufferedReader(new FileReader(somepath));
 reader.readLine(); // this will read the first line
 String line1=null;
 while ((line1 = reader.readLine()) != null){ //loop will run from 2nd line
        //some code
 }