1. Preface
Because comparing two pictures is the same, if you feel slower by Pixel point comparison, the efficiency is much lower when many images are compared. Since each file MD5 is essentially unique, it is used to determine whether the file is the same as the MD5 to get the file.
2. The code is as follows:
Import Java.io.fileinputstream;import Java.io.ioexception;import org.apache.commons.codec.digest.DigestUtils; Import Org.apache.commons.io.ioutils;public class TestMd5 {public static void main (string[] args) throws IOException {// TODO auto-generated method stubstring path= "C:\\philips\\siserver\\img\\p1.jpg"; String path2= "C:\\philips\\siserver\\img\\p2.jpg"; FileInputStream fis= New FileInputStream (path); String MD5 = Digestutils.md5hex (Ioutils.tobytearray (FIS)); ioutils.closequietly (FIS); System.out.println ("P1_MD5:" +md5); FileInputStream fis2= New FileInputStream (path2); String md52 = Digestutils.md5hex (Ioutils.tobytearray (FIS2)); ioutils.closequietly (FIS2); System.out.println ("P2_MD5:" +md52);}}
The log after execution is as follows:
P1_md5:699418360ea96b76c0d4cb701decd2e7
P2_md5:699418360ea96b76c0d4cb701decd2e7
3. Picture Resources
Link:p1.jpg p2.jpg is just rename p1.jpg.
[Java] uses MD5 to determine whether two files are identical