Posted on 2010-05-24 10:57
疯狂 阅读(1510)
评论(1) 编辑 收藏 所属分类:
java
1 File file = new File("test.zip");
2 FileInputStream fileInputStream = new FileInputStream(file);
3 byte[] buffer = new byte[1024];
4 DigestInputStream digestInputStream = new DigestInputStream(fileInputStream, MessageDigest.getInstance("md5"));
5 MessageDigest messageDigest = digestInputStream.getMessageDigest();
6 int i = -2;
7 while(i!=-1){
8 i = digestInputStream.read(buffer);
9 }
10 byte[] aftercode = messageDigest.digest();
11 System.out.println(Hex.encodeHex(aftercode));
12 digestInputStream.close();