获取文件的MD5值,比较两个文件是否完全相同
2024-09-28 08:03:11
代码:
public class MD5Test {
public static void main(String[] args) {
String s1 = MD5Test.MD5Operation(new File("E:/a.csv"));
String s2 = MD5Test.MD5Operation(new File("E:/data/a.csv"));
System.out.println(s1.equals(s2));
} public final static String MD5Operation(File file) {
try {
MessageDigest md = MessageDigest.getInstance("MD5");
//采用commons-io包的FileUt类的方法,极大地简化了代码。
byte temp[] = FileUtils.readFileToByteArray(file);
md.update(temp);
byte b[] = md.digest();
//采用java.math包的BigInteger类,实现十六进制的转换
BigInteger bigInt = new BigInteger(1, b);
return bigInt.toString(16);
} catch (Exception e) {
return null;
}
}
}
最新文章
- [转载]在SQL Server 中,如何实现DBF文件和SQL Server表之间的导入或者导出?
- Swift学习--常量.变量.数据类型的使用(一)
- ERP客户关系渠管理(二十)
- POJ 3176 Cow Bowling (水题DP)
- android——仿微拍贷滑动圆形菜单
- Css 之 px em %
- 调试大叔V1.0.1(2017.09.01)|http/s接口调试、数据分析程序员辅助开发神器
- windows 2008 R2操作系统上使用iis服务运行php和mysql数据库的网站遇到的验证码不显示问题?
- Python3.x 配置原生虚拟环境
- api_request.go
- 华为oj之字符个数统计
- axf 文件包含太多的调试信息,导致的编译错误
- yum源使用的几个报错小总结 (例如: python2.6.6 下yum不能使用: No module named yum)
- BZOJ4025 二分图(线段树分治+并查集)
- 第 3 章 镜像 - 019 - 使用公共 Registry
- 用node.js和webpack做前后端分离的总结
- 【AtCoder】ARC086
- pandas 的操作表单
- python的print()输出
- 推荐一个学习Flex chart的好网站