赞
踩
1.public static void main(String[] args){String img1 = md5(getByte("d:/test.JPG")); String img2 = md5(getByte("d:/test1.JPG")); if (img1.equals(img2)) System.out.println("两图片是一样的"); else System.out.println("两图片是不一样的");}
public static byte[] getByte(String name) { // 得到文件长度 File file = new File(name); byte[] b = new byte[(int) file.length()]; System.out.println(file.length()); try { InputStream in = new FileInputStream(file); try { in.read(b); System.out.println(in.read()); } catch (IOException e) { e.printStackTrace(); } } catch (FileNotFoundException e) { e.printStackTrace(); return null; } return b; }
/**
public static String md5(byte[] s) { // 16进制字符 char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; try { byte[] strTemp = s; MessageDigest mdTemp = MessageDigest.getInstance("MD5"); mdTemp.update(strTemp); byte[] md = mdTemp.digest(); int j = md.length; char str[] = new char[j * 2]; int k = 0; // 移位 输出字符串 for (int i = 0; i >> 4 & 0xf]; str[k++] = hexDigits[byte0 & 0xf]; } return new String(str); } catch (Exception e) { return null; } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。