views:

1220

answers:

2

how to convert tis-620 string to utf-8 string in java

+1  A: 
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;  
   }

Pass as encode argument "UTF-8"

sakana
still not working out quite right !!!
A: 
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);

Also, you might need to put charsets.jar on your classpath to support the TIS620 encoding.

izb