开发者

How to detect if two text files are identical in java

I would like to detect if file1.xml is different than file1.xmlCheck is there a way to do this in java?

I am plan开发者_StackOverflow中文版ning on having a guid as the only difference in the files.


Here's a link to a list of Open Source XML diff tools written in Java

http://www.manageability.org/blog/stuff/open-source-xml-diff-in-java


You might as well try the obvious and read the files in. You can read them character by character, block by block (say 1024 or 4096 characters at a time), or line by line and compare the strings you get.

If you know the exact location of your GUID and it's near the beginning or whatnot, you can build that into your comparison as well.

If you want line-by-line and you're using Java 1.5 or newer, look into java.util.Scanner; otherwise look into java.io.FileReader for character block reading.

(Note: If you don't have Java 1.5 or newer, you're stuck with FileReader)


You could run md5 on both files and compare the values.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜