将数据插入文本文件

问题描述:

欲插入在文本中的文件中的一些位置上的数据,而无需实际覆盖上的现有数据。我有两个文本文件。 one.txt的文件有1000行,two.txt来办到的文件有10000行。我想读one.txt文件内容并插入到前1000行two.txt来办到文件内容(附加one.txt的内容,以two.txt来办到的开头)。

I want to insert the data at some positions in the text file without actually overwriting on the existing data. I have two text file. "one.txt" file have 1000 lines, "two.txt" file have 10000 lines. I want to read "one.txt" file content and insert into first 1000 lines of "two.txt" file content(Append the content of "one.txt" to the beginning of "two.txt").

标准:


  • 最低代码

  • 少内存占用(不论编程语言)

  • 性能(将根据文件的大小来考虑)。

如果你不局限于C#中你可以做从Windows命令行:

If you're not limited to c# you can just do the following from a windows command line:

copy one.txt + two.txt three.txt

这将创造你想要的文件,但它会被称为three.txt。如果你必须two.txt拥有它,你可以简单地重命名two.txt别的东西先然后执行副本two.txt作为第三PARM追加。

This would create the file you want, but it would be called three.txt. If you must have it in two.txt, you could simply rename two.txt to something else first and then do the copy append with two.txt as the third parm.