开发者

Delete last N bytes from file

开发者 https://www.devze.com 2022-12-19 21:24 出处:网络
There\'s a file on disk which can be very large. Is there any way to delete the last N bytes from it without copying the remaining content to another f开发者_如何学Cile?How about this fragment of C# .

There's a file on disk which can be very large. Is there any way to delete the last N bytes from it without copying the remaining content to another f开发者_如何学Cile?


How about this fragment of C# .NET code?

FileInfo fi = new FileInfo("filename");
FileStream fs = fi.Open(FileMode.Open);

long bytesToDelete = 5000;
fs.SetLength (Math.Max(0, fi.Length - bytesToDelete));

fs.Close();


Additionally, if you want to add or remove bytes at any position: Insert, delete space at any place in file without making temporary file copy

0

精彩评论

暂无评论...
验证码 换一张
取 消