/**
* 读取文件MD5值
* @param file
* @return
*/
public static String getMd5ByFile(File file) throws FileNotFoundException {
String value="";
FileInputStream in=new FileInputStream(file);
try {
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());
value=bi.toString(16);
} catch (Exception e) {
e.printStackTrace();
}finally {
if(in!=null) {
try {
in.close();
} catch (Exception e2) {
e2.printStackTrace();
}
}
}
return value;
}
Java中获取文件的MD5值
最新推荐文章于 2024-07-10 03:17:51 发布