public class Md5CaculateUtil {
//这里给前端要求的头像图片的MD5
String imgFilePath = userInfo.getJSONArray("CUR_RESULT").getJSONObject(0).getString("XXXX");
if(imgFilePath!=null) {
File file = new File(imgFilePath);
String MD5 = getMD5(file);
userInfo.getJSONArray("CUR_RESULT").getJSONObject(0).put("MD5", MD5);
}
/**
* 获取一个文件的md5值(可处理大文件)
* @return md5 value
*/
public static String getMD5(File file) {
FileInputStream fileInputStream = null;
try {
MessageDigest MD5 = MessageDigest.getInstance("MD5");
fileInputStream = new FileInputStream(file);
byte[] buffer = new byte[8192];
int length;
while ((length = fileInputStream.read(buffer)) != -1) {
MD5.update(buffer, 0, length);
}
return new String(Hex.encodeHex(MD5.digest()));
} catch (Exception e) {
e.printStackTrace();
return null;
} finally
java 图片文件生成MD5值
最新推荐文章于 2025-06-24 21:15:01 发布