This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

RandomAccessFile Help  RSS feed

 
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
 
Bartender
Posts: 9521
12
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
Boost this thread!