Replacing text in a very large file

  • Thread starter Thread starter brianlivezey
  • Start date Start date
B

brianlivezey

I have a very large file containing fixed-length records. I'd like to
create a method to update one of those records without incurring the
cost of rewriting the entire file.

Is such a thing possible in C#? Nothing that I've seen in System.IO
seems appropriate.

Thanks!
Brian
 
I have a very large file containing fixed-length records. I'd like to
create a method to update one of those records without incurring the
cost of rewriting the entire file.

Is such a thing possible in C#? Nothing that I've seen in System.IO
seems appropriate.

FileStream FileMode.Open FileAccess.ReadWrite Seek Read Write

Arne
 
If you open a filestream on an existing file and start writing, you will
overwrite the contents of the file byte by byte. What you need to do is open
the file, work out how far into the file bytes the old record is. Seek that
number with the origin as beginning. The write the new record, This will
overwrite the data in the file.

HTH

Ciaran O'Donnell
 
Arne said:
FileStream FileMode.Open FileAccess.ReadWrite Seek Read Write

Very helpful! Got it working in just a few minutes with your hints.
Thank you!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top