new String(buffin,0,len,"gbk").getBytes("gb2312") != buffin
buffin  类型byte[]String --> byte[]-->String 怎么转?

解决方案 »

  1.   

    java技术交流,欢迎加入40652189,深入学习java的qq群,探讨新技术 
      

  2.   

    我用的就是相同的字符集
    public String StringDecrypt(String strSource) throws IOException
    {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    out.write(strSource.getBytes("GBK"));
    byte[] buff = out.toByteArray();
    out.close();
    for(int i=0;i< buff.length;i++)
    {
    buff[i] = DecyptWithGroup(buff[i]);
    }
    ByteArrayInputStream in = new ByteArrayInputStream(buff);
    int len = in.available();
    byte[] buffin = new byte[len];
    in.read(buffin);
    in.close();
    return new String(buffin,0,len,"GBK");

    最后返回的字符串new String(buffin,0,len,"GBK")
    而 new String(buffin,0,len,"GBK").getBytes("GBK") 得到的byte[] 中最后一个byte 和buffin中 最后一个不同
    我觉得太奇怪了! 我甚至想是不是new String(buffin,0,len,"GBK")得到的字符串添加东西了! 
      

  3.   

    Arrays.equals(byte[] a,byte[] a2)
      

  4.   

    各位大哥:小弟再把问题明了一下: 因为我做的是加解密,加密结果都是乱吗!所以问的问题有些不太确切!误解 这是我watch 出来的结果! 
    "buffin"= byte[8]  (id=21)
    [0]= 44
    [1]= -84
    [2]= -17
    [3]= 19
    [4]= -56
    [5]= -10
    [6]= 45
    [7]= -35"new String(buffin,0,len,"GBK").getBytes("GBK")"= byte[8]  (id=78)
    [0]= 44
    [1]= -84
    [2]= -17
    [3]= 19
    [4]= -56
    [5]= -10
    [6]= 45
    [7]= 63
    "new String(buffin,0,len,"GBK")"= ",撒-�"
    count= 6
    hash= 0
    offset= 0
    value= char[6]  (id=92)
    [0]= ,
    [1]= 
    [2]= 
    [3]= 撒
    [4]= -
    [5]= �
    到底怎么作才能使转化正确呢??
    到底怎么作才能使转化正确呢??
      

  5.   

    //string 转 byte[]
    String str = "中文字符";
    byte[] strbyte = str.getBytes();// byte[] 转 string
    String res = new String(strbyte);
    System.out.println(res);不要用String.valueof(strbyte).