【问题标题】:How can I edit big files? [duplicate]如何编辑大文件? [复制]
【发布时间】:2021-02-08 11:17:31
【问题描述】:

我需要编辑一个大文本文件(大约 100MB)。 我需要做的是找到一些文本,并用另一个文本替换它。 我看到了很多与that one类似的问题,但我想加载内存中的所有行会有内存问题吗? 有没有办法一一编辑行?最好的方法是什么?

【问题讨论】:

  • 这能回答你的问题吗? Edit a specific Line of a Text File in C#(特别是已接受答案的第二部分)
  • @FranzGleichmann 是的,谢谢,它似乎回答了我的问题,只是测试剩余:)
  • 我猜会有内存问题你试过了吗? 100MB 并不是很大。
  • @TaW 我仍在使用 Franz 建议的解决方案进行开发,尚未完成(我认为今天会完成)。 100MB 是我的例子,我想我什至可以获得 1Gb 或更多的文件。问题是是否有办法逐行编辑,但正如我在其他类似问题上阅读的那样,这是不可能的。

标签: c# file memory edit


【解决方案1】:

我会执行以下操作(伪代码):

Open source file
Create target file
for each line in source file
   target line = result of replacing some text in line
   write target line into target file
end for
close source and target files
replace source file with target file

这样你就不需要太多内存了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-05-31
    • 2023-03-26
    • 2021-07-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-10
    • 2019-06-27
    相关资源
    最近更新 更多