Search code examples
androidbufferedreaderskip

Skip first four lines using BufferedReader


For an App I am developing, I have a text file which I want to read using BufferedReader. The first four lines in the text file or not relevant though, so I do not want to read those. I looked at the documentation on BufferedReader, and I saw that I can use BufferedReader.skip(bytes) where I enter the amount of bytes to skip. However, the first four lines in the text file won't always contain the same amount of information so I think this is not really suitable for my purposes. Do you guys have an idea how to approach this some more practical way?


Solution

  • int lineNumber = 0;
    while ((s = br.readLine()) != null) {
        if (++lineNumber < 4)
            continue;
    
        // process next line
    }