目录
Demo
导入依赖
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.8.0</version>
</dependency>
示例代码
@Slf4j
public class CompareFiles {
public static void main(String[] args) {
String file1 = "D:/1.txt";
String file2 = "D:/2.txt";
Boolean flag = compareFiles(file1, file2);
System.out.println("==> " + flag);
}
public static Boolean compareFiles(String file1, String file2) {
try {
FileInputStream fileInputStream1 = new FileInputStream(new File(file1));
FileInputStream fileInputStream2 = new FileInputStream(new File(file2));
String s1 = DigestUtil.md5Hex(fileInputStream1);
String s2 = DigestUtil.md5Hex(fileInputStream2);
System.out.println(s1);
System.out.println(s2);
return s1.equals(s2);
} catch (FileNotFoundException e) {
log.error("文件不存在解析失败, {} ", e);
}
return false;
}
}
文章仅供学习交流,侵权联系删除。