码迷,mamicode.com
首页 > Windows程序 > 详细

C# download big file

时间:2019-11-10 15:52:06      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:static   ring   byte   void   out   big   color   const   http   


 static void Main(string[] args)
        {
            string url = "https://go.microsoft.com/fwlink/?linkid=2108895&clcid=0x409";
            DownloadBigFile(new Uri(url), "ssms.exe");             
        }

        static void DownloadBigFile(Uri url, string outputFilePath)
        {
            const int BUFFER_SIZE = 16 * 1024;
            using (var outputFileStream = File.Create(outputFilePath, BUFFER_SIZE))
            {
                var req = WebRequest.Create(url);
                using (var response = req.GetResponse())
                {
                    using (var responseStream = response.GetResponseStream())
                    {
                        var buffer = new byte[BUFFER_SIZE];
                        int bytesRead;
                        do
                        {
                            bytesRead = responseStream.Read(buffer, 0, BUFFER_SIZE);
                            outputFileStream.Write(buffer, 0, bytesRead);
                        } while (bytesRead > 0);
                    }
                }
            }
        }

 

static void Main(string[] args)
        {
            string url = "https://go.microsoft.com/fwlink/?linkid=866662";
            DownloadBigFile(new Uri(url), "sqlserver20192.exe");
            Console.ReadLine();
        }

        static void DownloadBigFile(Uri url, string outputFilePath)
        {
            const int BUFFER_SIZE = 16 * 1024;
            using (var outputFileStream = File.Create(outputFilePath, BUFFER_SIZE))
            {
                var req = WebRequest.Create(url);
                using (var response = req.GetResponse())
                {
                    using (var responseStream = response.GetResponseStream())
                    {
                        var buffer = new byte[BUFFER_SIZE];
                        int bytesRead;
                        do
                        {
                            bytesRead = responseStream.Read(buffer, 0, BUFFER_SIZE);
                            outputFileStream.Write(buffer, 0, bytesRead);
                        } while (bytesRead > 0);
                    }
                }
            }

 

C# download big file

标签:static   ring   byte   void   out   big   color   const   http   

原文地址:https://www.cnblogs.com/Fred1987/p/11829716.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!