Delete last N bytes from file

There is a file on disk, which can be very large. Is there a way to remove the last N bytes from it without copying the remaining contents to another file?

+6
io
source share
2 answers

What about this C # .NET code snippet?

FileInfo fi = new FileInfo("filename"); FileStream fs = fi.Open(FileMode.Open); long bytesToDelete = 5000; fs.SetLength (Math.Max(0, fi.Length - bytesToDelete)); fs.Close(); 
+10
source share

In addition, if you want to add or remove bytes at any position: Insert, delete a place anywhere in the file without temporarily copying files

0
source share

All Articles