1 public static String encodeFile(String path) {
 2 
 3         try {
 4             MessageDigest digester = MessageDigest.getInstance("MD5");
 5             
 6             FileInputStream in = new FileInputStream(path);
 7             
 8             byte[] bytes = new byte[1024];
 9             int byteCount;
10             while ((byteCount = in.read(bytes)) > 0) {
11                 digester.update(bytes, 0, byteCount);
12             }
13             byte[] digest = digester.digest();
14             
15             //用StringBuffer拼接字节数组
16             StringBuffer sb = new StringBuffer();
17             for (byte b : digest) {
18                 String str = Integer.toHexString(b & 0xff);
19                 if(str.length() == 1){
20                     str = "0" + str;
21                 }
22                 sb.append(str);
23             }
24             in.close();
25             
26             return sb.toString();
27             
28         } catch (Exception e) {
29             e.printStackTrace();
30         }
31         return null;
32     }

 

相关文章:

  • 2021-12-20
  • 2021-07-17
  • 2021-04-05
  • 2021-10-02
  • 2022-12-23
  • 2022-02-07
猜你喜欢
  • 2022-01-03
  • 2021-11-28
  • 2022-12-23
  • 2022-12-23
  • 2021-05-22
  • 2021-12-02
  • 2022-01-16
相关资源
相似解决方案