Here you can find the source of md5(File file)
public static String md5(File file) throws NoSuchAlgorithmException, IOException
//package com.java2s; // Licensed under the Apache License, Version 2.0 (the "License"); import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class Main { public static String md5(File file) throws NoSuchAlgorithmException, IOException { // try { // String s = PULSAR_CAUSTIC.getAbsolutePath(); // MessageDigest md5 = MessageDigest.getInstance("MD5"); // md5.update(s.getBytes(), 0, s.length()); // String signature = new BigInteger(1, md5.digest()).toString(16); // System.out.println("Signature: " + signature); ///*from w w w. j av a 2s . co m*/ // } catch (final NoSuchAlgorithmException e) { // e.printStackTrace(); // } MessageDigest md = MessageDigest.getInstance("MD5"); FileInputStream fis = new FileInputStream(file); byte[] dataBytes = new byte[1024]; int nread = 0; while ((nread = fis.read(dataBytes)) != -1) { md.update(dataBytes, 0, nread); } fis.close(); byte[] mdbytes = md.digest(); StringBuffer sb = new StringBuffer(); for (int i = 0; i < mdbytes.length; i++) { sb.append(Integer.toString((mdbytes[i] & 0xff) + 0x100, 16).substring(1)); } //System.out.println("Digest(in hex format):: " + sb.toString()); //assertEquals("8ff156ff36376d2517cef39cdd43876a", sb.toString()); return sb.toString(); } }