public static String fileMD5(File file) {
try(FileInputStream fileInputStream = new FileInputStream(file)) {
MessageDigest MD5 = MessageDigest.getInstance("MD5");
byte[] buffer = new byte[8192];
int length;
while ((length = fileInputStream.read(buffer)) != -1) {
MD5.update(buffer, 0, length);
}
return new String(Hex.encodeHex(MD5.digest()));
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public static String strMD5(String str) {
return DigestUtils.md5Hex(str);
}
JAVA计算文件MD5
最新推荐文章于 2024-05-04 18:00:17 发布