byte b[] = "你".getBytes("iso-10646-ucs-2");
String str = new String(b,"GB2312");

解决方案 »

  1.   

    byte b[] = "你".getBytes("iso-10646-ucs-2");
    getBytes的参数能是字符串吗?
      

  2.   

    不是字符串是什么?
    方法试出来了,应该是这样
    byte b[] = "你".getBytes("iso-10646-ucs-2");
    String str = new String(b,"iso-10646-ucs-2");
    有谁能给我一个解释吗?
      

  3.   

    unreported exception java.io.UnsupportedEncodingException;
    must be caugth or declared to be thrown
    String str=new String(b,"iso=10646-ucs-2");
    我编译的时候出现的问题我认为string.getBytes(int,int,byte[],int);
      

  4.   

    我测试了一下,iso-10646-ucs-2这个字符集很特殊啊。呵呵。
    查了一下,原来就是UTF-16啊。
    那就是了,UTF-16编码好像不能用getBytes()得到的编码转换,具体原因研究中.
      

  5.   

    你这样当然不行呀,由于你把字符串转为字节型后,然后你把它直接转为字符串型是不行的,由于它们的长度不一样,请看看下面的语句。
    byte array[]=new byte[1024];
    receivePacket=new DatagramPacket(array,array.length);
    recive appmess=new recive(); receiveSocket.receive(receivePacket);
    String received=new String(array,0,receivePacket.getLength());
    上面的语句是我做毕业设计的语句,可能不能直接体现出你的问题,但应该道理一样,
      

  6.   

    方法试出来了,应该是这样
    byte b[] = "你".getBytes("iso-10646-ucs-2");
    String str = new String(b,"iso-10646-ucs-2");
    有谁能给我一个解释吗?答:
    你的当前使用的字符集就是iso-10646-ucs-2;
      

  7.   

    同意楼上的
    你可以是把这个数组传到windows机器上应该可以用
    String str = new String(b,"GBK");