Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

RandomAccessFile Help

 
Nitin Gupte
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a text file with a path of another file on each line. I have a Java code that reads this file searches for the file on the particular line and takes it's contents. But in case of an error, it writes the line number to a temporary file so i can start exactly where i left. My problem is that the seek() method in RandomAccessFile class skips the number of bytes specified, not line numbers..
<QUOTE>
Is there any method any where in Java APIs which i can use to skip the specified lines from reading?
</QUOTE>
I want to avoid looping.. currently i using a loop n i say continue till i've reached the line number. I hope all this is making sense
 
Joe Ess
Bartender
Pie
Posts: 9264
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Nitin Gupte:

Is there any method any where in Java APIs which i can use to skip the specified lines from reading?

No. Files are just bytes. Line termination characters are particular bytes that we've agreed mean something special. There's no way to distinguish line terminators from other bytes without reading all of the bytes in.
You could, if you really needed this kind of functionality, make a file with fixed-length records, each record being a line padded to the maximum length. Then you could find a particular line by multiplying the record length by the line number. This, of course, comes with its own set of problems, like what the max line length is, how do you enforce it, how to insert and delete lines and so on.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic