Java获取图片的MD5
作者:互联网
File file = new File("/usr/local/face.jpg");
try {
FileInputStream fis = new FileInputStream(file);
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] buffer = new byte[1024];
int length = -1;
while ((length = fis.read(buffer, 0, 1024)) != -1) {
md.update(buffer, 0, length);
}
BigInteger bigInt = new BigInteger(1, md.digest());
System.out.println("文件md5值:" + bigInt.toString(16));
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
标签:md,Java,获取,buffer,printStackTrace,length,catch,new,MD5 来源: https://www.cnblogs.com/javalinux/p/16156430.html