I m trying to search the content of a fairly large file (5gb) using RandomAcessFile. Using binary search I divided the file into two parts , but such a strategy would work only when I would be able to read the line where the randomacessfile pointer points from the start. Since there is no guarantee that the pointer will point to the start of the file I need a way to position it to the start of the current line where it points. I referred the java docs but could not find a method that seeks the pointer to the start of the file. It does have a readLine() function but that would read the next line.
RandomAccessFile has no concept of "lines", as it is a byte-stream reader/writer, not a character-stream reader/writer. Using RandomAccessFile, your only option is to iterate backward until you find a newline character.