Java MD5 String md5file(File file)

Here you can find the source of md5file(File file)

Description

mdfile

License

Apache License

Declaration

public static String md5file(File file) throws Exception 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.math.BigInteger;
import java.security.MessageDigest;

public class Main {
    public static String md5file(File file) throws Exception {
        byte[] _bytes = null;
        InputStream is = new FileInputStream(file);
        MessageDigest digest = MessageDigest.getInstance("MD5");
        byte[] buffer = new byte[8192];
        int read = 0;
        while ((read = is.read(buffer)) > 0) {
            digest.update(buffer, 0, read);
        }//from  w  w w .j  a va  2s  . co m
        _bytes = digest.digest();
        if (is != null) {
            is.close();
            is = null;
        }
        return new BigInteger(1, _bytes).toString(16);
    }
}

Related

  1. md5encrypt(String phrase)
  2. md5Encrypt(String str)
  3. md5Encrypt(String str)
  4. md5Encryption(String str)
  5. md5File(File f)
  6. md5FromFile(File file)
  7. md5fromFile(String path)
  8. md5Hex(String data)
  9. md5Hex(String data)