I am trying to write to a file using a FileStream and want to write the second line and then write the first line. I use Seek() to go back to the beginning after writing the second line and then write the first line. It replaces the second line ( or part of it depending on the length of the first line.) How do I not make it replace the second line?
var fs = new FileStream("my.txt", FileMode.Create);
byte[] stringToWrite = Encoding.UTF8.GetBytes("string that should be in the end");
byte[] stringToWrite2 = Encoding.UTF8.GetBytes("first string\n");
fs.Write(stringToWrite, 0, stringToWrite.Length);
fs.Seek(0, SeekOrigin.Begin);
fs.Write(stringToWrite2, 0, stringToWrite2.Length);
Following is written to the file:
first string
hould be in the end
I want it to be
first string
string that should be in the end
Thanks