• 获取文件MD5值得方法


            /// <summary>
            /// 获取文件MD5值
            /// </summary>
            /// <param name="fileName">文件绝对路径</param>
            /// <returns>MD5值</returns>
            public static string GetMD5HashFromFile(string fileName)
            {
                try
                {
                    FileStream file = new FileStream(fileName, FileMode.Open);
                    System.Security.Cryptography.MD5 md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
                    byte[] retVal = md5.ComputeHash(file);
                    file.Close();
    
                    StringBuilder sb = new StringBuilder();
                    for (int i = 0; i < retVal.Length; i++)
                    {
                        sb.Append(retVal[i].ToString("x2"));
                    }
                    return sb.ToString();
                }
                catch (Exception ex)
                {
                    throw new Exception("GetMD5HashFromFile() fail,error:" + ex.Message);
                }
    
            }
    

      

  • 相关阅读:
    Java修饰符大汇总
    死锁
    线程的几种可用状态
    重载与覆盖(重写)
    Git
    JS跨域
    Spring中的Bean
    ZooKeeper
    Mysql(2)
    Maven
  • 原文地址:https://www.cnblogs.com/zxdz/p/13684807.html
Copyright © 2020-2023  润新知