Tags: binary, file, fromwebresponse, getresponsestream, huge, net, sharp, stream, write

How to write a huge stream to a file?

On .Net » .Net C# (C sharp)

851 words with 1 Comments; publish: Mon, 31 Dec 2007 13:06:00 GMT; (100140.63, « »)

All,

I want to write a big binary stream that was getting from

WebResponse.GetResponseStream() to a file. Anyone can help?

Thanks,

Rudy

All Comments

Leave a comment...

  • 1 Comments
    • Rudy Ko <rko.net-csharp.todaysummary.com.lucent.com> wrote:

      > I want to write a big binary stream that was getting from

      > WebResponse.GetResponseStream() to a file. Anyone can help?

      Sure. Open the stream to write to, and then just read blocks at a time

      out of GetResponseStream, writing them to the output stream. Stop when

      Read returns a value <= 0. Note that you must only write out the number

      of bytes read at any one time - don't assume that the buffer will have

      been filled.

      --

      Jon Skeet - <skeet.net-csharp.todaysummary.com.pobox.com>

      http://www.pobox.com/~skeet

      If replying to the group, please do not mail me too

      #1; Mon, 31 Dec 2007 13:07:00 GMT