Efficient way to combine multiple text files

后端 未结 3 542
南笙
南笙 2020-12-25 13:32

I have multiple files of text that I need to read and combine into one file. The files are of varying size: 1 - 50 MB each. What\'s the most efficient way to combine these f

3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-25 14:16

    Darin is on the right track. My tweak would be:

    using (var output = File.Create("output"))
    {
        foreach (var file in new[] { "file1", "file2" })
        {
            using (var input = File.OpenRead(file))
            {
                input.CopyTo(output);
            }
        }
    }
    

提交回复
热议问题