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
2008-10-29 11:50:25
still not working out quite right !!!
2008-10-30 09:36:34
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
2009-04-23 15:16:20