这个应该写在哪里啊
importjava.security.MessageDigest;
importjava.io.FileInputStream;
importjava.io.InputStream;
public class M D5 {
privatestatic final char HEX_DIGITS[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8','9', 'A', 'B', 'C', 'D', 'E', 'F' };
publicstatic void main(String[] args)
{
System.out.println(md5sum("/init.rc"));
}
publicstatic String toHexString(byte[] b) { //转化成16进制
StringBuildersb = new StringBuilder(b.length * 2);
for (int i = 0; i < b.length; i++) {
sb.append(HEX_DIGITS[(b[i]& 0xf0) >>> 4]);
sb.append(HEX_DIGITS[b[i] & 0x0f]);
}
returnsb.toString();
}
publicstatic String md5sum(String filename) {
InputStreamfis;
byte[]buffer = new byte[1024];
intnumRead = 0;
MessageDigestmd5;
try{
fis= new FileInputStream(filename);
md5 = MessageDigest.getInstance("MD5");
while((numRead=fis.read(buffer)) > 0) {
md5.update(buffer,0,numRead);
}
fis.close();
returntoHexString(md5.digest());
}catch (Exception e) {
System.out.println("error");
returnnull;
}
}
}