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()); }
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.
String strFile = File. ReadAllText("c:\\File1. txt"); strFile = strFile. Replace("oldvalue", "newvalue"); File.
To overwrite a file in Java, set the second argument of FileWriter to false .
You need to change the second parameter to false:
using (StreamWriter newTask = new StreamWriter("test.txt", false)){ newTask.WriteLine(name[i].ToString()); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With