I'm trying to read certain token from a line(say 3rd line from end). yesterday somebody suggested me to try with random access file. But I couldn't find a way to do it by that clas. seek() method take me to the certain position in that line. but first I need to go to that file.
Right now at first I'm reading that whole file and counting the number of line in it. then again I'm reading that file and going to that specific line(by substracting 3 from total number). I think its not a smart way to do this. is there any other way to do this by using "randon access file"?
Pls help me out here.
(1) getting the file length
(2) picking a buffer size
(3) read the last X bytes, where X is the buffer size
(4) keep a record of the line break positions
(5) if there are less than 3 read the 2nd to last X bytes