This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
    Bookmark Topic Watch Topic
  • New Topic

Fastest way of calculating MD5  RSS feed

adi arrab
Posts: 8
  • Mark post as helpful
  • send pies
  • Report post to moderator
I want to calculate MD5 values for a large Files I am using the following Code

public String Checker(File fi) throws NoSuchAlgorithmException,
FileNotFoundException {
MessageDigest md = MessageDigest.getInstance("MD5");
StopWatch stopWatch = new StopWatch();
InputStream is = new FileInputStream(fi);
byte[] buffer = new byte[4000];
int read = 0;
try {
while ((read = > 0) {
md.update(buffer, 0, read);
byte[] md5sum = md.digest();
BigInteger bigInt = new BigInteger(1, md5sum);
String output = bigInt.toString(16);
System.out.println("MD5 : " + output);
long s = stopWatch.getTime();
System.out.println("MD5 Time taken: " + s);
return output;
} catch (IOException e) {
throw new RuntimeException("Unable to process file for MD5", e);
} finally {
try {
} catch (IOException e) {
throw new RuntimeException(
"Unable to close input stream for MD5 calculation", e);


For Million record file it takes 55 seconds

How can i increase the performance(ie decrease the processing time)

Any Suggestions or Code would help

Thanks take care
Joe Ess
Posts: 9428
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Report post to moderator
Please don't post the same question more than once.
Carefully Choose One Forum
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!