关闭 FileChannel 打开的文件
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());
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。