Here you can find the source of createChecksum(File file, String shaAlgo)
public static String createChecksum(File file, String shaAlgo)
//package com.java2s; //License from project: Apache License import javax.xml.bind.DatatypeConverter; import java.io.File; import java.io.FileInputStream; import java.io.InputStream; import java.security.MessageDigest; public class Main { public static String createChecksum(File file, String shaAlgo) { try {//from w ww .j a v a2s . c o m InputStream fis = new FileInputStream(file); byte[] buffer = new byte[1024]; MessageDigest complete = MessageDigest.getInstance(shaAlgo); int numRead; do { numRead = fis.read(buffer); if (numRead > 0) { complete.update(buffer, 0, numRead); } } while (numRead != -1); fis.close(); return DatatypeConverter.printHexBinary(complete.digest()).toLowerCase(); } catch (Exception e) { throw new IllegalStateException( "could not create checksum for " + file + " and algo " + shaAlgo + ": " + e.getMessage(), e); } } }