Overwrite [or Delete] lines from text file [C#]

Shaitan00

Well-known member
Joined
Aug 11, 2003
Messages
343
Location
Hell
Using typical FileStream [Reader/Writer (sW)] I have successfully opened and navigated to the line I wish to replace by a given string
 
Last edited by a moderator:
i would suggest load the file and write each line as it is but only write for the wanted line the new line
so just load full content of a file and modify the text where you want and save it back as whole file
 
File can be way to large to load all at once.
There is no way of Overwriting or Deleting a Line in a File?
 
if you know exactly the byte position yes.. but if not then i would do it in that way:

read line for line while you get a line just check if you want to replace that one if not then write it in a temporary file when you finished that then just delete the old one and rename the temporary file to the filename of the old one
 
I guess I could figure out the byte position [no clue how but cant be that hard].

Because this text file could be VERY large and deleting/recreating it each time is a long process [and there are MANY of these files to go over].

There must be a simple way to overwrite the current contents of the line in a file.
 
Back
Top