简体   繁体   中英

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 planning 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)

您可以在两个文件上运行md5并比较这些值。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM