I suppose my title isn\'t that clear.
I\'ll try to explain:
I can write and read a file using a FileStream
FileStream fs = new FileStream(\"C
In your first example, you need to reset the stream before you write to it in order to replace the file contents, instead of appending to it:
private void button2_Click(object sender, EventArgs e)
{
fs.Seek(0,0);
fs.SetLength(Encoding.UTF8.GetBytes(textbox.Text).Length));
StreamWriter sw = new StreamWriter(fs);
sw.Write(textbox.Text);
sw.Flush();
}
If you truncate the stream down to 0, it will also work and no need to calculate the new file size in bytes.
fs.Seek(0,0);
fs.SetLength(0);