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         }
    下载服务器文件
  • 相关阅读:
    Java实现 LeetCode 209 长度最小的子数组
    Java实现 蓝桥杯 图书排列(全排列)
    Java实现 蓝桥杯 图书排列(全排列)
    Java实现 蓝桥杯 图书排列(全排列)
    C++11 FAQ中文版--转
    rtsp交互命令简介及过程参数描述
    PS流格式
    经典系统windows xp sp3官方原版下载(附XP序列号)
    Darwin Streaming Server 简介
    jrtplib跨网络通讯NAT穿透问题解决方法
  • 原文地址:https://www.cnblogs.com/dabexiong/p/7525506.html
Copyright © 2011-2022 走看看