我的要求
检查两个 csv/xml 是否相同,并且我不需要差异。
无需扫描整个内容并捕获两个文件之间的差异。一旦发现第一个差异,API 就必须返回。
请向我建议上述的最佳方法。
最佳答案
比较一下md5,看看两者的内容是否相同
public class DemoApplication {
public static void main(String[] args) throws IOException {
InputStream file1 = Files.newInputStream(Paths.get("/Documents/hello.txt"));
InputStream file2 = Files.newInputStream(Paths.get("/Documents/hello2.txt"));
String md5_file1 = org.apache.commons.codec.digest.DigestUtils.md5Hex(file1);
String md5_file2 = org.apache.commons.codec.digest.DigestUtils.md5Hex(file2);
if(md5_file1.equals(md5_file2)){
System.out.println("Same file");
}else{
System.out.println("It's not the same file");
}
}
}
关于java - 如何在java中检查两个csv/xml文件是否相同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60378764/