计算文件的 MD5 值

来源:互联网 发布:mac软件卸载不了 编辑:程序博客网 时间:2024/05/17 23:47
// 计算文件的 MD5 值
private String getFileMD5(File file)
{
if (!file.isFile())
{
return null;
}
MessageDigest digest = null;
FileInputStream in = null;
byte buffer[] = new byte[8192];
int len;
try
{
digest = MessageDigest.getInstance("MD5");
in = new FileInputStream(file);
while ((len = in.read(buffer)) != -1)
{
digest.update(buffer, 0, len);
}
BigInteger bigInt = new BigInteger(1, digest.digest());
return bigInt.toString(16);
}
catch (Exception e)
{
e.printStackTrace();
return null;
}
finally
{
try
{
in.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}


}
0 0
原创粉丝点击