• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

RandomAccessFile Help

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic