文件的完整性校验

/**
* get file md5
* @param file
* @return
* @throws NoSuchAlgorithmException
* @throws IOException
*/
private static String getFileMD5(File file) throws NoSuchAlgorithmException, IOException {
    if (!file.isFile()) {
        return null;
    }
    MessageDigest digest;
    FileInputStream in;
    byte buffer[] = new byte[1024];
    int len;
    digest = MessageDigest.getInstance("MD5");
    in = new FileInputStream(file);
    while ((len = in.read(buffer, 0, 1024)) != -1) {
        digest.update(buffer, 0, len);
    }
    in.close();
    BigInteger bigInt = new BigInteger(1, digest.digest());
    return bigInt.toString(16);

你可能感兴趣的:(文件的完整性校验)