public static byte[] md5FileToByte(File file) {
        if (file == null) return null;
        FileInputStream   fis               = null;
        DigestInputStream digestInputStream = null;
        try {
            fis = new FileInputStream(file);
            MessageDigest md = MessageDigest.getInstance("MD5");
            digestInputStream = new DigestInputStream(fis, md);
            byte[] buffer = new byte[256 * 1024];
            while (digestInputStream.read(buffer) > 0) ;
            md = digestInputStream.getMessageDigest();
            return md.digest();
        } catch (NoSuchAlgorithmException | IOException e) {
            e.printStackTrace();
            return null;
        } finally {
            IOKit.closeQuietly(fis);
            IOKit.closeQuietly(digestInputStream);
        }
    }
public static byte [ ] md5FileToByte ( File file ) { if ( file == null ) return null ; FileInputStream fis = null ; DigestInputStream digestInputStream = null ; try { fis = new FileInputStream ( file ) ; MessageDigest md = MessageDigest . getInstance ( "MD5" ) ; digestInputStream = new DigestInputStream ( fis , md ) ; byte [ ] buffer = new byte [ 256 * 1024 ] ; while ( digestInputStream . read ( buffer ) > 0 ) ; md = digestInputStream . getMessageDigest ( ) ; return md . digest ( ) ; } catch ( NoSuchAlgorithmException | IOException e ) { e . printStackTrace ( ) ; return null ; } finally { IOKit . closeQuietly ( fis ) ; IOKit . closeQuietly ( digestInputStream ) ; } }
MD5加密文件

@param file 文件
@return 文件的MD5校验码