C# download big file
程序员文章站
2023-10-16 16:51:18
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); } } }
推荐阅读
-
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
-
【转载】C#工具类:实现文件操作File的工具类
-
C# WebClient download image within url and display the downloaded picture automatically in windows os
-
C# Monitor and transfer or copy the changed or created file to a new location
-
C# read file to bytes,File.ReadAllFiles,File.Open(),BinaryReader
-
C# get md5,renamed file and can not change file's md5