美文网首页
文件的完整性校验

文件的完整性校验

作者: 王小宝wy | 来源:发表于2016-10-16 16:48 被阅读0次
    /**
    * 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);
    

    相关文章

      网友评论

          本文标题:文件的完整性校验

          本文链接:https://www.haomeiwen.com/subject/xetayttx.html