Obtain the MD5 value of the file and compare whether the two files are identical.

Source: Internet
Author: User


Public class md5test {public static void main (string [] ARGs) {string S1 = md5test. md5operation (new file ("E:/a.csv"); string S2 = md5test. md5operation (new file ("E:/data/a.csv"); system. out. println (s1.equals (S2);} public final static string md5operation (File file) {try {messagedigest MD = messagedigest. getinstance ("MD5"); // use the fileut class method of the commons-io package, greatly simplifying the code. Byte temp [] = fileutils. readfiletobytearray (File); Md. update (temp); byte B [] = md. digest (); // use Java. the biginteger class of the math package, which implements hexadecimal conversion of biginteger bigint = new biginteger (1, B); Return bigint. tostring (16) ;}catch (exception e) {return NULL ;}}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.