javabufferedreader

BufferedReader to skip first line


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?


Solution

  • 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
     }