早教吧作业答案频道 -->其他-->
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();
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 呢,都没有改变啊.
但是我看你这个读法有问题吧;
在循环中怎么一直都从 0 都到 1024 呢,都没有改变啊.
看了 Winform下载文件问题S...的网友还看了以下:
会c#的麻烦进来帮下忙using System;using System.Collections. 2020-05-16 …
1,I didn’t mean to take a taxi but I had to as I 2020-05-17 …
A.system hardwareB.system softwareC.keyboardD.oper 2020-05-26 …
A.system commandsB.system callsC.system transferD. 2020-05-26 …
修改系统变量 Path 的值为%System Root%\ System32;% System Ro 2020-05-31 …
LotteryDrawing.java的问题.苦思冥想想不出来numbersr=numbersn- 2020-06-12 …
C#考试用!急~混分别来~留下详细过程!83.假设变量x的值为25,要输出x的值,下列正确的语句是 2020-06-14 …
用for循环语句编写满足条件的程序(java)只用下列语句:System.out.print("" 2020-07-17 …
Runtimert=Runtime.getRuntime()importjava.util.*;p 2020-07-17 …
Winform下载文件问题System.Net.HttpWebRequestMyrq=(Syste 2020-08-04 …