Java MD5 String md5(File f)

Here you can find the source of md5(File f)

Description

md

License

Open Source License

Declaration

public static String md5(File f) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.security.DigestInputStream;
import java.security.MessageDigest;

public class Main {
    public static String md5(File f) {
        MessageDigest md = null;/*from w ww .  j  ava  2s .  co  m*/
        InputStream is = null;
        try {
            md = MessageDigest.getInstance("MD5");
            is = new FileInputStream(f);
            is = new DigestInputStream(is, md);
            byte[] buffer = new byte[8192];
            while (is.read(buffer) != -1) {
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                is.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        byte[] digest = md.digest();
        return digest.toString();
    }
}

Related

  1. md5()
  2. md5(File f)
  3. md5(File f)
  4. md5(File f)
  5. md5(File file)
  6. md5(File file)
  7. md5(File file)