I think you cannot read the contents of the file. Therefore, if you can "open" it with write access only:
using (var fileStream = File.Open("initDoc.txt", FileMode.Open, FileAccess.Write))
{
fileStream.SetLength(fileStream.Length - 4);
}
Of course, you will need additional checks to make sure that you subtract the correct number of bytes depending on the encoding, and do not subtract more than the length, etc.
FileMode.Open, FileStream, SafeFileHandle. SafeFileHandle , # Interop. , "UnmanagedFileLoader":
var unmanagedFileLoader = new UnmanagedFileLoader("initDoc.txt");
using (var fileStream = new FileStream(unmanagedFileLoader.Handle, FileAccess.Write))
{
fileStream.SetLength(fileStream.Length - 4);
}
UnmanagedFileLoader CreateFile :
handleValue = CreateFile(Path, GENERIC_WRITE, 0, IntPtr.Zero, OPEN_EXISTING, 0, IntPtr.Zero);
, SafeFileHandle, :
http://msdn.microsoft.com/en-us/library/microsoft.win32.safehandles.safefilehandle%28v=vs.110%29.aspx
FileStream, - StreamReader StreamWriter, StreamReader 4 , StreamWriter. - FileStream.