• 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

How to seek start and end points in File?

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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???
 
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic