• Post Reply Bookmark Topic Watch Topic
  • New Topic

File pointers  RSS feed

 
Vallabhaneni Suresh Kumar
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can any one suggest me how to use file pointers in Java. I had an sequential file and for that file I have to set file pointer for the first record and for the last record. How can I achieve this in Java?
 
Julian Kennedy
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I understand you correctly, look at java.io.RandomAccessFile.

Jules
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Important question: do all records have the same lentgth? If so, you will be able to calculate the position of any record in the file:

position = recordNumber * recordLength + headerLength.

If the records aren't all the same size, you will probably need to read each record sequentially to find out where it begins and ends. There are many possible wayt to do this; what works best will depend on the record format. For fast access in the future it might well be helpful to build an index indicating where each record begins - but that's no use the first time you read the file. (Unless someone else has already built such an index for you.)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!