Java – Get MD5 Checksum of a File

The Apache Commons Codec could help you to generate the MD5 of a file with just one command. Download the lib @ Download Commons Codec. If you want to use Maven, include the following dependency in the pom.xml.



Try the following example.

package com.wordpress.ykyuen;


import org.apache.commons.codec.digest.DigestUtils;

public class GenerateMd5 {

  public static void main(String[] args) {
    FileInputStream fis = null;
    try {
      // Generate md5
      fis = new FileInputStream("C:\\Users\\Administrator\\Desktop\\");
      String md5String = DigestUtils.md5Hex(fis);
    } catch (FileNotFoundException e) {
    } catch (IOException e) {


Done =)

Reference: StackOverflow – using Java to get a file’s md5 checksum?

8 thoughts on “Java – Get MD5 Checksum of a File”

  1. There’s no md5Hex method with InputStream as a parameter. I can see only md5Hex(byte[] data) or md5Hex(java.lang.String data)


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.