比如有两或两个以上的文件流,
byte[] b1=File.ReadAllBytes(Path1);
byte[] b2=File.ReadAllBytes(Path2);
...
现在要b1与b2合并成一个文件流!!!
还请大家指教!!!!!

解决方案 »

  1.   

    很犀利,我看CSDN有人提出和你一样的问题,我就不发链接了,你可以找下!
      

  2.   

    合并
    byte1.CopyTo(newByte, 0);
    byte2.CopyTo(newByte, byte1.length)
    Array.Copy
      

  3.   

    直接上dos命令 
    copy fileA+fileB fileCfileC即是合并的文件流
      

  4.   


    请问一下C#怎样执行DOS命令呢
      

  5.   

    new个process()            Process process = new Process();
                process.StartInfo.FileName = 要执行的文件名;
                process.StartInfo.Arguments = 参数;
                process.StartInfo.CreateNoWindow = true;
                process.Start(); 
      

  6.   

    这是2个字节数组,不完全是stream,
    实际使用起来,我认为不要直接合并为好,当大数据量的时候造成浪费内存,以及可能导致溢出。比如写个读取指定长度的函数byte[] getbytes(int len);
    定一个int pos下标,>0,<b1.Lenght+b2.Length
    函数根据要求,返回pos起始位置的len字节数据。如果pos+len<b1.lenght,那么直接从b1里copy部分内容,如果pos>b1.lenght,直接读取b2从pos-b1.lenght起始位置的len字节数据
    如果pos<b1.lenght且pos+len>b1.length,那么读取b1的尾部部分+b2的头部部分合并输出。输出玩后pos+=len。
      

  7.   


    private List<string> files = new List<string>();// 需要合并的文件
    public List<string> Files
    {
    get { return files; }
    }
    public void Combine(string fullName)
    {
    byte []buffer = new byte[1024*100];
    using (FileStream outStream = new FileStream(fullName, FileMode.Create))
    {
    int readedLen = 0;
    FileStream srcStream = null;
    for (int i = 0; i < files.Count; i++)
    {
    srcStream = new FileStream(files[i], FileMode.Open);
    while ((readedLen = srcStream.Read(buffer, 0, buffer.Length)) > 0)
    {
    outStream.Write(buffer, 0, readedLen);
    }
    srcStream.Close();
    }
                }
    }