欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C#利用WebClient實(shí)現(xiàn)兩種方式下載文件

 更新時(shí)間:2017年02月06日 14:29:25   作者:x4646  
本篇文章主要介紹了C#利用WebClient 兩種方式下載文件,詳細(xì)的介紹了兩種方式,非常具有實(shí)用價(jià)值,需要的朋友可以參考下。

最近整理了WebClient 兩種方式下載文件 ,留作以后查詢(xún)。

第一種

string URLAddress = @"http://xiazai.jb51.net";

string receivePath=@"C:\";

client.DownloadFile(URLAddress, receivePath + System.IO.Path.GetFileName(URLAddress));

 就OK了。

第二種

 Stream str = client.OpenRead(URLAddress);
 StreamReader reader = new StreamReader(str);
 byte[] mbyte = new byte[1000000];
 int allmybyte = (int)mbyte.Length;
 int startmbyte = 0;

 while (allmybyte > 0)
 {

 int m = str.Read(mbyte, startmbyte, allmybyte);
 if (m == 0)
  break;

 startmbyte += m;
 allmybyte -= m;
 }

 reader.Dispose();
 str.Dispose();

 string path = receivePath + System.IO.Path.GetFileName(URLAddress);
 FileStream fstr = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write);
 fstr.Write(mbyte, 0, startmbyte);
 fstr.Flush();
 fstr.Close(); 

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論