Here you can find the source of md5File(File f)
public static String md5File(File f)
//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 md5File(File f) { MessageDigest md = null;/*from www . ja v a 2s. com*/ InputStream is = null; try { md = MessageDigest.getInstance("MD5"); is = new FileInputStream(f); is = new DigestInputStream(is, md); // read stream to EOF as normal... byte[] buffer = new byte[4096];//allocate a small array. while (is.read(buffer) != -1) { } //read file in chunks } catch (Throwable ignore) { //don't care. ignore.printStackTrace(); return null; } finally { if (null != is) { try { is.close(); } catch (IOException ignore) { } } } if (null != md) { return toHexString(md.digest()); } return null; } public static String toHexString(byte[] bytes) { StringBuffer sb = new StringBuffer(); for (int i = 0; i < bytes.length; i++) { sb.append(Integer.toHexString(0xff & bytes[i])); } return sb.toString(); } }