Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to overwrite data in a txt file? [duplicate]

Tags:

Possible Duplicate:
Can any one tell why the previous data is still displayed while saving data using StreamWriter

I have WPF C# application, that reads and writes to a .txt file, i know how to write line but line, but how do I overwrite the text that is already the file. This is what I have just to write to the next line of the text file, but I want to over the lines not just write to the next line, thanks.

using (StreamWriter newTask = new StreamWriter("test.txt", true))  {     newTask.WriteLine(name[i].ToString());     } 
like image 260
Beef Avatar asked Jun 22 '11 19:06

Beef


People also ask

How do you overwrite a text?

Turn on Overtype modeIn the Word Options dialog box, choose Advanced. Under Editing options, do one of the following: To use Insert key to control Overtype mode, select the Use Insert key to control overtype check box. To keep Overtype mode enabled always, select the Use overtype mode check box.

How do you overwrite a text file in C#?

String strFile = File. ReadAllText("c:\\File1. txt"); strFile = strFile. Replace("oldvalue", "newvalue"); File.

How do you override a text file in Java?

To overwrite a file in Java, set the second argument of FileWriter to false .


1 Answers

You need to change the second parameter to false:

using (StreamWriter newTask = new StreamWriter("test.txt", false)){          newTask.WriteLine(name[i].ToString()); } 
like image 182
Ryan Gross Avatar answered Oct 25 '22 17:10

Ryan Gross