如何在Java中将TIS-620字符串转换为UTF-8字符串?

时间:2008-10-29 11:42:51

标签: java string type-conversion

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

2 个答案:

答案 0 :(得分: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”

答案 1 :(得分:1)

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编码。