Copying from one stream to another?

前端 未结 4 2107
伪装坚强ぢ
伪装坚强ぢ 2021-02-09 03:07

For work, the specification on my project is to use .Net 2.0 so I don\'t get the handy CopyTo function brought about later on.

I need to copy the response s

4条回答
  •  悲哀的现实
    2021-02-09 03:55

    This is a handy function. And yes, the buffer size matters. Increasing it might give you better performance on large files.

    public static void WriteTo(Stream sourceStream, Stream targetStream)
    {
           byte[] buffer = new byte[0x10000];
           int n;
           while ((n = sourceStream.Read(buffer, 0, buffer.Length)) != 0)
               targetStream.Write(buffer, 0, n);
    }
    

提交回复
热议问题