java md5加密驗證兩個檔案的內容是否相同
阿新 • • 發佈:2019-01-22
1.首先新建兩個內容相同的檔案
2.建立測試類
public class TestMD5 {
public static void main(String[] args) {
try {
FileInputStream file1 = new FileInputStream(new File("C:\\Users\\hp\\Desktop\\md51.txt"));
FileInputStream file2 = new FileInputStream(new File("C:\\Users\\hp\\Desktop\\md52.txt" ));
System.out.println(DigestUtil.md5Hex(file1));
System.out.println(DigestUtil.md5Hex(file2));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
列印結果:
202cb962ac59075b964b07152d234b70
202cb962ac59075b964b07152d234b70
3.修改md52.txt的內容
4.列印結果
202cb962ac59075b964b07152d234b70
81dc9bdb52d04dc20036dbd8313ed055