- import java.io.FileInputStream;
- public class Auth{
- public static byte[] create(String filename) throws Excepiton{
- InputStream fis = new FileInputStream(filename);
- byte[] buf= new byte[1024];
- MessageDigest com=MessageDigest.getInstance("MD5");
- int num;
- do{
- num=fis.read(buf);
- if(num>0){
- com.update(buf,0,num);
- }
- }while(num!=-1)
- fis.close();
- return com.digest();
- }
- public static String getMD5(String filename) throw Exception {
- byte[] b =create(filename);
- String result="";
- for(int i=0;i<b.length;i++){
- result+=Integer.toString( (b[i]&0xff)+0x100,16).substring(1);
- }
- return result;
- }
- }
来源: http://www.bubuko.com/infodetail-2983573.html