public static void main(String[] args) throws NoSuchAlgorithmException {
File file = new File("D:\\downloadFile\\20220224\\536907087_2022022400.047891ce6534e88f2ab777829ead3021.txt.gz");
FileInputStream inputStream = null;
FileOutputStream outputStream = null;
MessageDigest md = MessageDigest.getInstance("MD5");
try {
inputStream = new FileInputStream(file);
byte[] bytes = new byte[10240];
int len;
while (( len = inputStream.read(bytes)) != -1){
md.update(bytes,0,len);
}
//加密结果
inputStream.close();
String md5 = Hex.encodeHexString(md.digest());
System.out.println("加密结果:"+md5);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
java实现md5加密文件
于 2022-02-24 15:01:51 首次发布