file reading/writing

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
I need to read a file and simultaneously modify the same file , i.e, read
a file and then change some contents in it and then save it once again.

How do I do this?

Thanks,
 
Hi Venkat,

Try reading the file, modify in memory and write everything back to the
file.
 
Hello Venkat,

Your problem is way too vague to actually answer with a single answer.

Let's say you have a file that is not composed of fixed length strings. The
file contains the string "ABC DEF GHI" and you want to replace this entire
string with "ZYX". Well, the new string is shorter than the old one... so
you have to move up the rest of the bytes in the file to fill in the "hole"
you left. On the other hand, you may be substituting a longer string, and
your problem is reversed. What if you want to make more than one change in
a pass? What if you have pattern matching logic that you need to apply?

And these considerations are different if you are talking about updating the
contents of a file containing only fixed length records, or using a more
complicate encoding scheme like Shift-JIS, or using a structured mechanism
like XML sitting on top of character encoding.

If you'd like to ask a more specific question, or at least provide some
insight into the nature of your data, you may get more specific answers to
your questions.

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
 
Back
Top