What would be the fastest way to concatenate three files in C#?

后端 未结 7 1778
滥情空心
滥情空心 2020-11-29 07:40

I need to concatenate 3 files using C#. A header file, content, and a footer file, but I want to do this as cool as it can be done.

Cool = really small code or reall

7条回答
  •  暖寄归人
    2020-11-29 08:05

    I would go this route...

        FileStream fStream = new FileStream("outputpath", FileMode.Append);
        foreach (string item in new string[] { "file1", "file2", "file3" })
            fStream.Write(File.ReadAllBytes(item));
        fStream.Close();
    

    Not file size dependent, no concatenation, and avoiding any possible encoding/decoding issues by reading/writing bytes.

提交回复
热议问题