WebClient client = new WebClient();

 

第一种

 

string URLAddress = @"https://files.cnblogs.com/x4646/tree.zip";

 

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();

 

相关文章:

  • 2021-07-04
  • 2021-08-07
  • 2022-02-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-13
猜你喜欢
  • 2022-03-04
  • 2021-10-07
  • 2022-02-12
  • 2021-08-26
  • 2022-12-23
  • 2021-11-26
相关资源
相似解决方案