Java tutorial
//package com.java2s; public class Main { public static String calculateMd5Checksum(String filename) { String result = ""; try { byte[] b = createChecksumBytes(filename, "MD5"); // convert bytes to HEX strings for (int i = 0; i < b.length; i++) { result += Integer.toString((b[i] & 0xff) + 0x100, 16).substring(1); } } catch (Exception ex) { throw new RuntimeException("Error: " + ex.toString(), ex); } return result; } public static byte[] createChecksumBytes(String filename, String checksumType) throws java.io.IOException, java.security.NoSuchAlgorithmException { if (checksumType == null) { // MD5 by default checksumType = "MD5"; } java.io.InputStream fis = new java.io.FileInputStream(filename); byte[] buffer = new byte[1024]; java.security.MessageDigest complete = java.security.MessageDigest.getInstance(checksumType); int numRead = 0; do { numRead = fis.read(buffer); if (numRead > 0) { complete.update(buffer, 0, numRead); } } while (numRead != -1); fis.close(); return complete.digest(); } }