如何快速下载大量的小文件?
我的目的是下载大量的小图片。
我创建了24条线程,每条线程都单独地下载一个图片,刚开始用的是My.Computer.Network.DownloadFile,总感觉速度不够快。然后在网上搜懂到了这个代码:
Dim DownloadBlock As Integer = 1024
Dim theResponse As HttpWebResponse
Dim theRequest As HttpWebRequest
theRequest = WebRequest.Create("这是下载地址")
theResponse = theRequest.GetResponse
Dim writeStream As New IO.FileStream("这是保存路径")
Do
Dim readBytes(DownloadBlock - 1) As Byte
Dim bytesread As Integer = theResponse.GetResponseStream.Read(readBytes, 0, DownloadBlock)
If bytesread = 0 Then Exit Do
writeStream.Write(readBytes, 0, bytesread)
Loop
theResponse.GetResponseStream.Close()
writeStream.Close()