i = new String(str.getBytes("gb2312"),-4).getBytes().length;
警告The constructor String(byte[], int) is deprecated查API是这样解释
String(byte[] ascii, int hibyte) 
          已过时。 该方法无法将字节正确地转换为字符。从 JDK 1.1 开始,完成该转换的首选方法是使用带有 Charset、字符集名称,或使用平台默认字符集的 String 构造方法。
用Charset怎么实现。

解决方案 »

  1.   

    new String("".getBytes(), "UTF-8")
      

  2.   

    i =new String("".getBytes(), "gb2312") 
      

  3.   

    new String("".getBytes("iso-88591-1"), "UTF-8")
      

  4.   

    new String("".getBytes(), "GBK")
      

  5.   

    new String("".getBytes(), "UTF-8"),so easy
      

  6.   

    new String("".getBytes("iso-88591-1"), "UTF-8")
    和new String("".getBytes(), "UTF-8")都可以使用,但是lz你要根据自己的具体。
    new String("".getBytes("iso-88591-1"), "UTF-8") 是把iso-8859-1 转成UTF-8
      

  7.   

    new String("".getBytes("iso-88591-1"), "UTF-8")
    zhengjie