早教吧 育儿知识 作业答案 考试题库 百科 知识分享

Winform下载文件问题System.Net.HttpWebRequestMyrq=(System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(URL);System.Net.HttpWebResponsemyrp=(System.Net.HttpWebResponse)Myrq.GetResponse();longtotalByt

题目详情
Winform 下载文件问题
System.Net.HttpWebRequest Myrq = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(URL);
System.Net.HttpWebResponse myrp = (System.Net.HttpWebResponse)Myrq.GetResponse();
long totalBytes = myrp.ContentLength;
System.IO.Stream st = myrp.GetResponseStream();
System.IO.Stream so = new System.IO.FileStream(filename, System.IO.FileMode.Create);
long totalDownloadedByte = 0;
byte[] by = new byte[1024];//这里的1024指定的是缓冲区大小吗 还是只能下载1024字节的文件
osize = st.Read(by, 0, (int)by.Length);
while (osize > 0)
{
totalDownloadedByte = osize + totalDownloadedByte;
System.Windows.Forms.Application.DoEvents();
so.Write(by, 0, osize);
osize = st.Read(by, 0, (int)by.Length);
}
so.Close();
▼优质解答
答案和解析
1024是指定读取的缓存大小.
但是我看你这个读法有问题吧;
在循环中怎么一直都从 0 都到 1024 呢,都没有改变啊.