c# - How do I truncate a file X bytes from the end? -
Let's say that there is a file that is 150 bytes long and I want to shorten it to the previous 16 (or any number) Wish me from the end ...
Is there any other way than writing the whole file again?
Update: SetLength should do this, but unfortunately NotSupportedException has been thrown
using (file stream fsFinalWrite = new FileStream (FileName, FileMode Open, File Access. Read-White, FileShare. Read-White)) {FSFANl World. Sec (16, Siocone. And); FsFinalWrite.Write (SwappedBytes, 0, 16); Debug Witterite ("FSFinalWrite =" + Debug FSFinal WorldCart. Wrightite ("FsFinalWrite can write =" + FsFinalWrite.CanWrite); fsFinalWrite.SetLength ((long) lengthOfFile);}
Both prints are true! But still it throws a NotSupportedException. How does anyone handle it?
About FileStream.SetLength ()
?
Comments
Post a Comment