Forums Register Login

Line based access with RandomAccessFile

+Pie Number of slices to send: Send
Hi
Is there some sort of abstraction available over RandomAccessFile that let me jump(seek) to a specified line number in the file.
Any help appreciated!
+Pie Number of slices to send: Send
I believe you have to write your own class. I would extend RandomAccessFile and implement CharSequence, and then use this class in Pattern and Matcher to find EOL sequence.
+Pie Number of slices to send: Send
This isn't very useful, because the point of a RandomAccessFile is to provide, well, random access. If you need to find the number of lines in a file, whether you do this with a Pattern or otherwise, you still end up reading the entire file up to the point you want to jump to.

Simply wrap the file in a Scanner or a BufferedReader or something.
+Pie Number of slices to send: Send
Its only useful if the size of each line is a fixed length. Then in this case you can randomly read line.
Hey, I'm supposed to be the guide! Wait up! No fair! You have the tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1599 times.
Similar Threads
SCJD help
java I/O
Reading strings from file
Modifying a text file without using a temp file
questions about several File methods.
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 18, 2024 22:56:30.