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());
}
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。