• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to seek start and end points in File?  RSS feed

 
vijay mahendra
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

In my application ,I need to find start position and end position in File. After that, delete text between start position and end position.
Again , i need to update with new data in same position.

Now i am using RandomAcesssFile. seek method for start position.
using same seek method i can find end position also.But i am unable to find update text between start/end positions or delete also.
please help me in this.
Thanks one and all.
 
Norm Radder
Rancher
Posts: 1734
22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure I understand your question.
For example what do you mean by delete. For example given the string ABC, if I delete the B I end up with AC, a 2 char string. Or do you want A C, a 3 character string with the B overwritten with a space?

For the first case, you'll need to rewrite the file by dragging the data following the end of the deleted data to where the deleted data used to be and then to truncate the file the new length.

For the second case, just overwrite the area to be deleted with an appropriate character that represents deleted data???
 
Praveen Seluka
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One way is by using RandomAccessFile's write method to write data from the start point.Seek to the start point and start writing data.It will over-write the existing text.By this way you can update the text in between

But the problem is since you are replacing the text , the new text should be as big as the text to be replaced.Any work arounds please

Thanks
Praveen SP
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!