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

  • 相关阅读:
    struts2 DMI
    MFC添加背景图片
    c++ 副本构造器
    climits
    Qt中的qreal
    Http概述(一)
    重构学习-重构原则
    QDir的mkdir和mkpath区别
    Qt学习笔记网络(一)
    Qt5 新特性
  • 原文地址:https://www.cnblogs.com/xibei666/p/4359134.html
Copyright © 2011-2022 走看看