Efficient way to delete a line from a text file

前端 未结 8 1904
暖寄归人
暖寄归人 2020-11-29 11:09

I need to delete a certain line from a text file. What is the most efficient way of doing this? File can be potentially large(over million records).

UPDATE: below is

8条回答
  •  暖寄归人
    2020-11-29 12:05

    In my blog, I have benchmarked various I/O methods from C# in order to determine the most efficient way of doing file I/O. In general, you are better off using the Windows ReadFile and WriteFile functions. The next fastest way to read files in is through FileStream. To get good performance, read the files in blocks at a time instead of a line at a time and then do your own parsing. The code that you can download from my blog gives you an example on how to do this. There is also a C# class that encapsulates the Windows ReadFile / WriteFile functionality and is quite easy to use. See my blog for details at:

    http://designingefficientsoftware.wordpress.com/2011/03/03/efficient-file-io-from-csharp

    Bob Bryan MCSD

提交回复
热议问题