public class test3
{
    public static void main(String[] args) throws Exception
    {
MessageDigest hash = null;
hash = MessageDigest.getInstance("MD5");
byte[] xxx= hash.digest("hello".getBytes());
hash.reset();
byte[] yyy= hash.digest("hello".getBytes());
byte[] zzz= hash.digest("hello".getBytes()); for(int i=0;i<16;i++)
    System.out.println(xxx[i]+"  "+yyy[i]+"  "+zzz[i]); System.out.println(xxx);
System.out.println(yyy);
System.out.println(zzz);
    }
}结果是这样的93  93  93
65  65  65
64  64  64
42  42  42
-68  -68  -68
75  75  75
42  42  42
118  118  118
-71  -71  -71
113  113  113
-99  -99  -99
-111  -111  -111
16  16  16
23  23  23
-59  -59  -59
-110  -110  -110
[B@c17164
[B@1fb8ee3
[B@61de33
为什么
System.out.println(xxx);
System.out.println(yyy);
System.out.println(zzz);
这三句是一样的东西输出来的不一样的呢?

解决方案 »

  1.   

    System.out.println()
    这个pintln方法,当参数为byte[]时,调用的是
    println(Object obj)
    这个方法,里面使用了Object的toString方法。
    println方法只对char[]提供了直接的支持。
      

  2.   

    File file = new File("store","public.txt");
    FileInputStream instream=new FileInputStream(file);
    byte[] public= new byte[(int)file.length()];
    inputstream.read(public);这样可以把file里面存的读到public里面去吗?