获取数据的md5值版权声明
原创public class MD5Utils {
public static void main(String[] args) throws Exception{
File file = new File("D:\\msdia80.dll");
String md5 = MD5Utils.getMD5(new FileInputStream(file));
System.out.println(md5);
}
/**
* 把文件拿来。MD5值
*/
public static String getMD5(InputStream in) {
MessageDigest digest = null;
byte buffer[] = new byte[1024 * 1024];
int len;
try {
digest = MessageDigest.getInstance("MD5");
while ((len = in.read(buffer, 0, 1024 * 1024)) != -1) {
digest.update(buffer, 0, len);
}
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
throw new SunawException("把文件拿来。MD5错误");
} catch (IOException e) {
e.printStackTrace();
throw new SunawException("把文件拿来。MD5错误");
}
BigInteger bigInt = new BigInteger(1, digest.digest());
return bigInt.toString(16);
}
}
版权声明
所有资源都来源于爬虫采集,如有侵权请联系我们,我们将立即删除
上一篇:MyBatis-Spring配置大体了解版权声明 下一篇:idea中解决矛盾