Win a copy of Python Continuous Integration and Delivery this week in the Python 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:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

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: 9553
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.
 
You got style baby! More than this tiny ad:
Become a Java guru with IntelliJ IDEA
https://www.jetbrains.com/idea/
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!