zoukankan      html  css  js  c++  java
  • 我的Tools

     1         /// <summary>
     2         /// 计算文件大小函数(保留两位小数),Size为字节大小
     3         /// </summary>
     4         /// <param name="Size">初始文件大小</param>
     5         /// <returns></returns>
     6         public static string CountSize(long Size)
     7         {
     8             string m_strSize = "";
     9             long FactSize = 0;
    10             FactSize = Size;
    11             if (FactSize < 1024.00)
    12                 m_strSize = FactSize.ToString("F2") + " Byte";
    13             else if (FactSize >= 1024.00 && FactSize < 1048576)
    14                 m_strSize = (FactSize / 1024.00).ToString("F2") + " K";
    15             else if (FactSize >= 1048576 && FactSize < 1073741824)
    16                 m_strSize = (FactSize / 1024.00 / 1024.00).ToString("F2") + " M";
    17             else if (FactSize >= 1073741824)
    18                 m_strSize = (FactSize / 1024.00 / 1024.00 / 1024.00).ToString("F2") + " G";
    19             return m_strSize;
    20         }
    计算文件大小函数(保留两位小数),Size为字节大小
     1         /// <summary>
     2         /// 下载服务器文件
     3         /// </summary>
     4         /// <param name="local_path">本地文件路径+文件</param>
     5         /// <param name="remote_path">远程文件路径+文件</param>
     6         public static void downloadRemote(string local_path, string remote_path)
     7         {
     8             HttpWebRequest request = WebRequest.Create(remote_path) as HttpWebRequest;
     9             HttpWebResponse response = request.GetResponse() as HttpWebResponse;
    10             Stream responseStream = response.GetResponseStream();
    11             Stream stream = new FileStream(local_path, FileMode.Create);
    12             byte[] bArr = new byte[1024];
    13             int size = responseStream.Read(bArr, 0, (int)bArr.Length);
    14             while (size > 0)
    15             {
    16                 stream.Write(bArr, 0, size);
    17                 size = responseStream.Read(bArr, 0, (int)bArr.Length);
    18             }
    19             stream.Close();
    20             responseStream.Close();
    21         }
    下载服务器文件
  • 相关阅读:
    开放就像死亡访问之后就能回头——Leo鉴书84
    将博客搬至CSDN
    将博客搬至CSDN
    滚动条
    Perl Pack写的一个数据报表程序
    利用hash 数组打印标题
    Linux显示只显示目录文件
    Linux显示按文件名降序文件
    Linux显示以时间生升序显示文件
    Linux显示按文件大小降序排列
  • 原文地址:https://www.cnblogs.com/dabexiong/p/7525506.html
Copyright © 2011-2022 走看看