错误已经在代码中标出。
private void downfile()
{
string url="https://www.test.com/downfile?w=AFKSDFSLGFD-SDFE";
string FileName;
WebClient DownFile = new WebClient();
long fbytes;
if (url != "")
{
FileName = @"c:\save.xml";
if (FileName != "")
{
//取得文件大小
WebRequest wr_request = WebRequest.Create(url);
WebResponse wr_response = wr_request.GetResponse();
fbytes = wr_response.ContentLength;
wr_response.Close();
//开始下载数据
Stream strm = DownFile.OpenRead(url);//报错为找不到文件
StreamReader reader = new StreamReader(strm);
byte[] mbyte = new byte[fbytes];
int allmybyte = (int)mbyte.Length;
int startmbyte = 0;
while (fbytes > 0)
{
int m = strm.Read(mbyte, startmbyte, allmybyte);
if (m == 0) break;
startmbyte += m;
allmybyte -= m;
}
FileStream fstrm = new FileStream(FileName, FileMode.OpenOrCreate, FileAccess.Write);
fstrm.Write(mbyte, 0, startmbyte);
strm.Close();
fstrm.Close();
}
}
else
{
MessageBox.Show("没有文件!");
}
}
private void downfile()
{
string url="https://www.test.com/downfile?w=AFKSDFSLGFD-SDFE";
string FileName;
WebClient DownFile = new WebClient();
long fbytes;
if (url != "")
{
FileName = @"c:\save.xml";
if (FileName != "")
{
//取得文件大小
WebRequest wr_request = WebRequest.Create(url);
WebResponse wr_response = wr_request.GetResponse();
fbytes = wr_response.ContentLength;
wr_response.Close();
//开始下载数据
Stream strm = DownFile.OpenRead(url);//报错为找不到文件
StreamReader reader = new StreamReader(strm);
byte[] mbyte = new byte[fbytes];
int allmybyte = (int)mbyte.Length;
int startmbyte = 0;
while (fbytes > 0)
{
int m = strm.Read(mbyte, startmbyte, allmybyte);
if (m == 0) break;
startmbyte += m;
allmybyte -= m;
}
FileStream fstrm = new FileStream(FileName, FileMode.OpenOrCreate, FileAccess.Write);
fstrm.Write(mbyte, 0, startmbyte);
strm.Close();
fstrm.Close();
}
}
else
{
MessageBox.Show("没有文件!");
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货