ImportJava.io.File;ImportJava.io.FileInputStream;Importjava.io.FileNotFoundException;Importjava.io.IOException;ImportJava.math.BigInteger;Importjava.security.MessageDigest;Importjava.security.NoSuchAlgorithmException; Public classTest { Public Static voidMain (string[] args) {Try{File File=NewFile ("F://test.txt"); FileInputStream FIS=Newfileinputstream (file); MessageDigest MD= Messagedigest.getinstance ("MD5"); byte[] buffer =New byte[1024]; intLength =-1; while(length = fis.read (buffer, 0, 1024))! =-1) {md.update (buffer,0, length); } BigInteger bigInt=NewBigInteger (1, Md.digest ()); System.out.println ("File MD5 value:" + bigint.tostring (16)); } Catch(FileNotFoundException e) {e.printstacktrace (); } Catch(nosuchalgorithmexception e) {e.printstacktrace (); } Catch(IOException e) {e.printstacktrace (); } }}
Java gets the MD5 value of the file