No - because in order to know how many lines there are, something needs to look at each character along the way to see if it's a \r or \n. Without knowing where each line boundary is, there's no way to know what the line count is, or where each line begins. You could write a class which does this work for you, making it look like you're getting random access, but you still need to read all the bytes up to line n, at least once.
"I'm not back." - Bill Harding, Twister
posted 16 years ago
I built myself a custom class that indexes the new lines in a file according to byte position.
Just call and it returns a long that gives the byte position of that line in the file. Then you can use your RandomAccessFile object to seek that byte position. Here's the code for ByteInderxer:
[ May 14, 2004: Message edited by: Prashant Sehgal ]