I have a fixed format file.
I want to access specific lines in this file based on line numbers.
e.g. read line 100
The length of each line is 200 bytes.
So directly moving cursor to 100th line using RandomAccessFile would be like:
File f = new File(myFile);
RandomAccessFile r = new RandomAccessFile(f,"rw");
r.skipBytes(200 * 99); // linesize * (lineNum - 1)
System.out.println(r.readLine());
However, I am getting output as null.
What am I missing here ?
The question is in continuation to answer to my previous question Reaching a specific line in a file using RandomAccessFile
Update:
Below program works exactly as I am expecting:
Line size is 200 characters.
File f = new File(myFile);
RandomAccessFile r = new RandomAccessFile(f,"rw");
r.seek(201 * (lineNumber-1)); // linesize * (lineNum - 1)
System.out.println(r.readLine());
Giving linenumber (any line number from entire file) is printing that line.
@EJP: Please explain!