|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Write to an existing ASCII fileMy experience with reading/writing files is to open one file, read it into
memory close it and open another file and write to it. Now I would like to learn how to read and write to the same file. My problem is that I need to open a file, read the first line, change the line somewhat and write the line back to the file (overwriting the original line). Can anyone help? Thanks, Mark "Mark" <M***@discussions.microsoft.com> schrieb: Check out 'System.IO.StreamWriter', 'System.IO.StreamReader' (samples in the > My experience with reading/writing files is to open one file, read it into > memory close it and open another file and write to it. > > Now I would like to learn how to read and write to the same file. My > problem is that I need to open a file, read the first line, change the > line > somewhat and write the line back to the file (overwriting the original > line). documentation) and 'System.Text.Encoding.Ascii'. Note that stream reader and writer accept an encoding in their constructors. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> Hi Mark,
Open the File as a FileStream object using the New FileStream("FileName", FileMode, FileAccess) constructor and set the FileAccess to 'ReadWrite'. Then, use a StreamReader to read, and a StreamWriter to write data, as reqd. Regards, Cerebrus. "Mark" <M***@discussions.microsoft.com> wrote in message If the new line is longer or shorter than the original line, what should news:9BE1059E-45B0-4956-BA9C-38776DA250F1@microsoft.com... > Now I would like to learn how to read and write to the same file. My > problem is that I need to open a file, read the first line, change the > line > somewhat and write the line back to the file (overwriting the original > line). happen? |
|||||||||||||||||||||||