private static String getMd5ByFile(File file) throws IOException {
String md5Value = null;
if (!file.canRead()) {
return null;
}
try (FileInputStream in = new FileInputStream(file)) {
MappedByteBuffer byteBuffer = in.getChannel().map(FileChannel.MapMode.READ_ONLY, 0, file.length());
MessageDigest md5 = MessageDigest.getInstance("MD5");
md5.update(byteBuffer);
BigInteger bi = new BigInteger(1, md5.digest());
md5Value = bi.toString(16);
} catch (Exception e) {
e.printStackTrace();
}
return md5Value;
}
传入一个文件流对象,读取MD5返回
最新推荐文章于 2024-04-29 05:09:56 发布