private String ISO2Gb_W(String str) {
    try {
      return new String(str.getBytes("GBK"),"8859_1");
      }catch(Exception ex) {}
      return "null";
  }

解决方案 »

  1.   

    回复人: josy(风尘浪子) ( ) 信誉:98  2005-03-18 08:59:00  得分: 0  
     
     
       private String ISO2Gb_W(String str) {
        try {
          return new String(str.getBytes("GBK"),"8859_1");
          }catch(Exception ex) {}
          return "null";
      }
    --------------------------------------------------
    楼上正解,建议楼主多看JDK的文档
      

  2.   

    以上楼主都行啦!是的,应多查JDK文档
      

  3.   

    to shinya(逸风):
        你的意思是把中文字符串转换成字节数组吗?
      

  4.   

    嗯,我先转成了"ISO8859-1",在new String以前至少应该是"GBK"的byte数组
    如何数组转数组?就是这个问题
      

  5.   

    我的一点观点,不知道正确否。
    String value = "测试";
    byte[] temp = value.getByte("ISO8859-1");
    这两句执行完后,temp数组的长度是2个字节。
    因为value占四个字节,你转换的时候已经有信息丢失了。
    靠temp数组已经不能转回来了吧
      

  6.   

    感觉楼上说得有道理,不过应该可以转转中文,通过unicode中转
      

  7.   

    public byte[] getBytes(String charsetName)
                    throws UnsupportedEncodingException      Encodes this String into a sequence of bytes using the named charset, storing the result into a new byte array. 
    The behavior of this method when this string cannot be encoded in the given charset is unspecified. The CharsetEncoder class should be used when more control over the encoding process is required. 
    你看文档的解释:当string不能被编码的给定的字符集的时候,这个方法的行为是未知的。
      

  8.   

    同意楼上,在jdk文档中写的很清楚了!