你查查api啊,String(byte[] bytes) 就是把字节数组转化成字符串,而getBytes()就是把字符串还原为字节数组,当然一样了。

解决方案 »

  1.   

    我的代码就是先把字节数组result转化为字符串str,再把字符串转化为字节数组result1。result和result1的值不同。
    而把他们转化为字符串的值确是相同的。这怎么解释啊?
    我想让result 和result1相同,得怎么做?
      

  2.   

    我觉得是解码和编码时不匹配而出现问题
    你试一试用:
    String str = new String(result,"ISO8859-1");
    //...
    byte[] result1 = str.getBytes("ISO8859-1");
    //...
      

  3.   

    使用ByteArrayOutputStream怎样        byte[] result={61,111,-40,1,-84,-82,-47,53};
            ByteArrayOutputStream bas=new ByteArrayOutputStream();
            bas.write(result);
      

  4.   

    import java.io.*;
    import java.math.*;
    import java.util.*;public class te {
        
        /** Creates a new instance of te */
        public te() {
        }    public static void main(String[] args)throws IOException {
    byte[] result={61,111,-40,1,-84,-82,-47,53};
     for(int i =0; i < 8;i++)
     System.out.print(result[i] + "  "); //result位byte数组
     System.out.println(); String str = new String(result,"ISO8859-1");
     System.out.println("E: "+str); byte[] result1 = str.getBytes("ISO8859-1");
     System.out.println(new String(result1)); for(int i =0; i < 8;i++)
     System.out.print(result1[i] + "  ");
     System.out.println();
        }
        
    }
      

  5.   

    import java.io.*;
    import java.math.*;
    import java.util.*;public class te {
        
        /** Creates a new instance of te */
        public te() {
        }    public static void main(String args[])throws IOException {
    byte[] result={61,111,-40,1,-84,-82,-47,53};
    for(int i =0; i < 8;i++)
    System.out.print(result[i] + "  "); //result位byte数组
    System.out.println();

    String str = new String(result,"ISO8859-1");
    System.out.println("E: "+str);

    byte[] result1 = str.getBytes("ISO8859-1");
    System.out.println(new String(result1,"ISO8859-1"));//设置编码方式

    for(int i =0; i < 8;i++)
    System.out.print(result1[i] + "  ");
    System.out.println();
        }
        
    }