How do I download a large file (via HTTP) in .NET?

前端 未结 6 1185
余生分开走
余生分开走 2021-02-01 18:03

I need to download a large file (2 GB) over HTTP in a C# console application. Problem is, after about 1.2 GB, the application runs out of memory.

Here

6条回答
  •  無奈伤痛
    2021-02-01 18:30

    WebClient.OpenRead returns a Stream, just use Read to loop over the contents, so the data is not buffered in memory but can be written in blocks to a file.

提交回复
热议问题