打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
文件md5计算


public static String getFileMD5String(File file) throws IOException {
System.out.println("**************************");
System.out.println(file.toString());
System.out.println("**************************");
@SuppressWarnings("resource")
FileInputStream in = new FileInputStream(file);
FileChannel ch = in.getChannel();
MappedByteBuffer byteBuffer = ch.map(FileChannel.MapMode.READ_ONLY, 0,
file.length());
messageDigest.update(byteBuffer);
/*
* in.close(); in = null; byteBuffer.clear(); byteBuffer = null;
* ch.close(); ch = null;
*/
if(file.length() > 0){
Method getCleanerMethod;
sun.misc.Cleaner cleaner = null;
try {
getCleanerMethod = byteBuffer.getClass().getMethod("cleaner",
new Class[0]);
getCleanerMethod.setAccessible(true);
cleaner = (sun.misc.Cleaner) getCleanerMethod
.invoke(byteBuffer, new Object[0]);
cleaner.clean();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return bufferToHex(messageDigest.digest());
}

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
java nio 之MappedByteBuffer,高效文件/内存映射
在java中如何遍历某个路径下的所有文件夹和文件
JAVA中indexOf函数用法
java中对IO文件的操作(读,写,增加一行,删除一行,删除文件
java创建文件和目录
java中io操作小例子
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服