public static String md5(File file) throws NoSuchAlgorithmException, FileNotFoundException, IOException { MessageDigest md = MessageDigest.getInstance("MD5"); InputStream is = new FileInputStream(file); byte[] buffer = new byte[8192]; int read = 0; while ((read = is.read(buffer)) > 0) md.update(buffer, 0, read); byte[] md5 = md.digest(); BigInteger bi = new BigInteger(1, md5); is.close(); String hex = bi.toString(16); while (hex.length() < 32) { hex = "0" + hex; } // Padding return hex; }