/**
* 获取文件的MD5值
* @param file
* @return
*/
public static String getFileMD5(File file) {
String s = null;
if (!file.exists()) {
return null;
}
FileInputStream in = null;
byte buffer[] = new byte[1024];
int len;
try {
MessageDigest md = MessageDigest.getInstance("MD5");
in = new FileInputStream(file);
while ((len = in.read(buffer, 0, 1024)) != -1) {
md.update(buffer, 0, len);
}
in.close();
BigInteger bigInt = new BigInteger(1, md.digest());
s = String.format("%032X", bigInt);//如果想要返回小写的md5串,把这里的%032X改为小写%032x即可
} catch (Exception e) {
e.printStackTrace();
return null;
}
return s;
}
* 获取文件的MD5值
* @param file
* @return
*/
public static String getFileMD5(File file) {
String s = null;
if (!file.exists()) {
return null;
}
FileInputStream in = null;
byte buffer[] = new byte[1024];
int len;
try {
MessageDigest md = MessageDigest.getInstance("MD5");
in = new FileInputStream(file);
while ((len = in.read(buffer, 0, 1024)) != -1) {
md.update(buffer, 0, len);
}
in.close();
BigInteger bigInt = new BigInteger(1, md.digest());
s = String.format("%032X", bigInt);//如果想要返回小写的md5串,把这里的%032X改为小写%032x即可
} catch (Exception e) {
e.printStackTrace();
return null;
}
return s;
}