java 二进制 文件比较,比较Java中的两个文档

I have two word documents which i am trying to compare in java .

I tried using

md5 hashcode

HashCode newFile = Files.asByteSource(newFileInput).hash(Hashing.md5());

HashCode oldFile = Files.asByteSource(oldFileInput).hash(Hashing.md5());

and also using,

boolean isEqual = FileUtils.contentEquals(oldFile , newFile);

Even though the contents are same ,compared the content using online tools and beyond compare,

still the hashcode in both above method comes as MISMATCH.

any solutions? or way to compare any file type using any API in Java.

i need to do deep compare between two word files as in for spaces,fonts , content. etc..

Expected Result : Both file should match

解决方案

Even if both of your documents look the same or even if both contains the same formatted content, a slightly change like the last modified date will result in a failed comparison. JSON documents are more easier to compare but Word documents are binary. The smallest change can change the document completely.

So you have to do it the hard way: Find a library to read the content of the Word files by yourself and check the content of both files specifically.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值