Created
August 28, 2015 01:53
-
-
Save ixqbar/835f3fb9718ad01f00d3 to your computer and use it in GitHub Desktop.
java md5sum file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.FileInputStream; | |
import java.security.MessageDigest; | |
public class TestCheckSum { | |
public static void main(String args[]) throws Exception { | |
String datafile = "c:\\INSTLOG.TXT"; | |
MessageDigest md = MessageDigest.getInstance("SHA1"); | |
FileInputStream fis = new FileInputStream(datafile); | |
byte[] dataBytes = new byte[1024]; | |
int nread = 0; | |
while ((nread = fis.read(dataBytes)) != -1) { | |
md.update(dataBytes, 0, nread); | |
}; | |
byte[] mdbytes = md.digest(); | |
//convert the byte to hex format | |
StringBuffer sb = new StringBuffer(""); | |
for (int i = 0; i < mdbytes.length; i++) { | |
sb.append(Integer.toString((mdbytes[i] & 0xff) + 0x100, 16).substring(1)); | |
} | |
System.out.println("Digest(in hex format):: " + sb.toString()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment