0

I am reading a 15 Million file using Java BUfferReader. In some conditions, I have to loop back 1000 lines in the buffer and RE-READ them, and then continuing them with the next records after those 1000. In simple words I want to be able to have full control over line number in the buffer during the loop.

1) The BufferReader.mark(1000000) and BufferReader.Reset() simply hangs in big files.

2) If I use Randomaccessfile, The seek() method requires an offset rather than a simple line number which makes the program complex.

So, what is the best way if I want to move back 1000 lines (again and again) if a certain condition arises.

THanks

Noman K
  • 277
  • 1
  • 5
  • 15
  • 3
    You shouldn't have to do this. Almost any file can be processed in a single pass. If a Java compiler can do it, you can. If you really have this problem, just keep the last 1000 lines in a list and update it every time you read a new line, removing the first item and adding a new last item. – user207421 Jul 24 '14 at 00:49
  • 2
    @EJP 1k lines [sliding window](https://en.wikipedia.org/wiki/Sliding_Window_Protocol), very nice. – Elliott Frisch Jul 24 '14 at 00:55

0 Answers0