How do I save a stream to a file in C#?

后端 未结 10 2405
我寻月下人不归
我寻月下人不归 2020-11-22 03:06

I have a StreamReader object that I initialized with a stream, now I want to save this stream to disk (the stream may be a .gif or .jpg

10条回答
  •  余生分开走
    2020-11-22 04:12

    public void testdownload(stream input)
    {
        byte[] buffer = new byte[16345];
        using (FileStream fs = new FileStream(this.FullLocalFilePath,
                            FileMode.Create, FileAccess.Write, FileShare.None))
        {
            int read;
            while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
            {
                 fs.Write(buffer, 0, read);
            }
        }
    }
    

提交回复
热议问题