如何使用字节数组附加文档文件



我正在尝试使用字节数组将多个文件附加到单个文件中,但是当我尝试附加文件时,它只转换最后一个文件。 我使用以下代码:

            byte[] outputBytes = new byte[0];
            byte[] temp1 = System.IO.File.ReadAllBytes(@"D:2.doc");
            byte[] temp2 = System.IO.File.ReadAllBytes(@"D:3.doc");
            outputBytes = new byte[temp1.Length + temp2.Length];
            Buffer.BlockCopy(temp1,0,outputBytes,0,temp1.Length * sizeof(byte));
            Buffer.BlockCopy(temp2,0,outputBytes,0,temp2.Length  * sizeof(byte));
            System.IO.File.WriteAllBytes(@"D:myOutPut.doc",outputBytes);

我正在创建一个显示所有文件内容的输出文件。

谢谢。

您需要

使用第二个BlockCopy设置dstOffset

Buffer.BlockCopy(temp1, 0, outputBytes, 0, temp1.Length * sizeof(byte));
Buffer.BlockCopy(temp2, 0, outputBytes, temp1.Length, temp2.Length * sizeof(byte));

但我认为您不能将文档文件与此连接起来。

最新更新