zoukankan      html  css  js  c++  java
  • 客户端文件下载

    using system.Net

    WebClient client = new WebClient();

    第一种

    string URLAddress = @"http://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();

    转载:http://www.cnblogs.com/x4646/archive/2013/04/11/3014634.html

  • 相关阅读:
    kvm介绍
    正式班D24
    正式班D23
    正式班D21
    正式班D20
    正式班D19
    正式班D18
    正式班D17
    正式班D16
    正式班D15
  • 原文地址:https://www.cnblogs.com/xibei666/p/4359134.html
Copyright © 2011-2022 走看看