0

I have a requirement where I have to read nth line (let's take it 3rd) from the end of the 20 GB file.I cannot load the complete file in the memory and also I cannot split the file into small files.

Do I have to read from 1st line orIs there any other way I can do this in java, maybe by patching or extending FileReader or Buffer reader?

Delphi
  • 71
  • 1
  • 8
  • 1
    Possible duplicate of [How to read a specific line using the specific line number from a file in Java?](https://stackoverflow.com/questions/2312756/how-to-read-a-specific-line-using-the-specific-line-number-from-a-file-in-java) – Raju Sharma Oct 13 '17 at 11:04
  • 1
    There is a [ReversedLinesFileReader](https://commons.apache.org/proper/commons-io/javadocs/api-2.4/org/apache/commons/io/input/ReversedLinesFileReader.html) in Apache Commons apparently, that might be useful. – Karl Reid Oct 13 '17 at 11:05
  • 1
    you can also download [`tail` source code](https://stackoverflow.com/q/1439799/995714) to see how they implemented the feature – phuclv Oct 13 '17 at 11:09
  • Thanks Karl for replying. If I use ReversedLinesFileReader will it load the entire file into the memory? – Delphi Oct 13 '17 at 11:09
  • I don't think it would load the whole file into memory - it's a buffered reader, so it should read the file in blocks. There's some discussion [here](https://stackoverflow.com/a/45445038/7852370). – Karl Reid Oct 13 '17 at 11:12

0 Answers0