zoukankan      html  css  js  c++  java
  • 获取文件的md5值

    public class MD5Utils {
    
        public static void main(String[] args) throws Exception{
            File file = new File("D:\msdia80.dll");
            String md5 = MD5Utils.getMD5(new FileInputStream(file));
            System.out.println(md5);
        }
    
    
        /**
         * 获取文件的MD5值
         */
        public static String getMD5(InputStream in) {
            MessageDigest digest = null;
            byte buffer[] = new byte[1024 * 1024];
            int len;
    
            try {
                digest = MessageDigest.getInstance("MD5");
                while ((len = in.read(buffer, 0, 1024 * 1024)) != -1) {
                    digest.update(buffer, 0, len);
                }
            } catch (NoSuchAlgorithmException e) {
                e.printStackTrace();
                throw new SunawException("获取文件的MD5错误");
            } catch (IOException e) {
                e.printStackTrace();
                throw new SunawException("获取文件的MD5错误");
            }
            BigInteger bigInt = new BigInteger(1, digest.digest());
            return bigInt.toString(16);
        }
    }
  • 相关阅读:
    dex文件格式三
    神庙逃亡破解分析
    MySQL优化
    Redis AOF和RDB
    KD树
    关系型和非关系型数据库
    数据库实现分布式锁
    单点登录
    数据库树形结构查询
    层次遍历递归和非递归方法
  • 原文地址:https://www.cnblogs.com/tanyucong/p/11775579.html
Copyright © 2011-2022 走看看