C# download big file
程序员文章站
2022-06-05 18:58:05
static void Main(string[] args) { string url = "https://go.microsoft.com/fwlink/?linkid=2108895&clcid=0x409"; DownloadBigFile(new Uri(url), "ssms.... ......
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); } } }
上一篇: Pandas数据分析④——数据规整2(数据拼接/透视)
下一篇: 二叉树的遍历
推荐阅读
-
c#使用file.copy实现文件备份示例
-
C#的File类实现文件操作实例详解
-
C#中File类的文件操作方法详解
-
C#中File类的文件操作方法详解
-
C# copy files from source directory to destination file and rename repeated files and does not override
-
C#删除只读文件或文件夹(解决File.Delete无法删除文件)
-
C# transfer local file to remote server based on File.Copy
-
C#中对文件File常用操作方法的工具类
-
C# extract img url from web content then download the img
-
C# download big file