Use FileStream , find the end of the file, then write what you need:
using (var fs = new FileStream(s, FileMode.Open, FileAccess.ReadWrite)) { fs.Seek(SeekOrigin.End); fs.Write(data, 0, data.Length); }
If you really need to read the entire file, just use Array.Resize to make your buffer larger, and copy the part you want to add.
var data = File.ReadAllBytes(s); Array.Resize(ref data, data.Length + toAppend.Length); Array.Copy(toAppend, 0, data, data.Length - toAppend.Length, toAppend.Length); File.WriteAllBytes(s, data);
There is no “shorthand” for this, sorry.: \
If the whole point of this is to add a line, just use File.AppendAllText !
Mehrdad
source share