【问题标题】:How to convert TIS-620 string to UTF-8 string in Java? [closed]如何在 Java 中将 TIS-620 字符串转换为 UTF-8 字符串? [关闭]
【发布时间】:2008-10-29 11:42:50
【问题描述】:

如何在 Java 中将 TIS-620(扩展的 ASCII Thai 字符代码页)字符串转换为 UTF-8 字符串?

【问题讨论】:

    标签: java string type-conversion


    【解决方案1】:
    import java.nio.ByteBuffer
    import java.nio.CharBuffer
    

    ....

    public static ByteBuffer toByteBuffer(String content, String encode) {  
          Charset charset = Charset.forName(encode);  
          ByteBuffer bb = charset.encode(content);  
           return bb;  
       }  
    

    作为编码参数“UTF-8”传递

    【讨论】:

    • 还是不太对劲!!!
    【解决方案2】:
    private byte[] convertTis620ToUTF8(byte[] encoded)
    {
        try
        {
            String theString = new String(encoded, "TIS620");
            return theString.getBytes("UTF-8");
        } 
        catch(UnsupportedEncodingException uee)
        {
            /* Didn't work out */
        }
    }
    
    ...
    
    byte[] utf8 = convertTis620ToUTF8(tis620);
    

    此外,您可能需要将 charsets.jar 放在类路径中以支持 TIS620 编码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-23
      • 2012-06-25
      • 1970-01-01
      • 2017-06-14
      • 2010-09-21
      • 1970-01-01
      • 2015-11-14
      • 2016-09-02
      相关资源
      最近更新 更多