我的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         }
下载服务器文件
原文地址:https://www.cnblogs.com/dabexiong/p/7525506.html