java计算文件MD5值

public static void main(String[] args) throws ParseException, IOException {

      try {
              File file = new File("C://Users//Administrator//Desktop//aabb//OverviewInfo-201904-20190506185734-03.txt");
              FileInputStream fis = new FileInputStream(file);
              MessageDigest md = MessageDigest.getInstance("MD5");
              byte[] buffer = new byte[1024];
              int length = -1;
              while ((length = fis.read(buffer, 0, 1024)) != -1) {
                md.update(buffer, 0, length);
             }
              BigInteger bigInt = new BigInteger(1, md.digest());
              System.out.println("文件md5值:" + bigInt.toString(16));
           } catch (FileNotFoundException e) {
              e.printStackTrace();
          } catch (NoSuchAlgorithmException e) {
               e.printStackTrace();
          } catch (IOException e) {
               e.printStackTrace();
          }

}

发布了118 篇原创文章 · 获赞 59 · 访问量 49万+

猜你喜欢

转载自blog.csdn.net/u012255097/article/details/102964769