How do I convert TIS-620 (the extended ASCII Thai Character code page) string to UTF-8 string in Java?
如何在Java中将TIS-620(扩展的ASCII泰语字符代码页)字符串转换为UTF-8字符串?
2 个解决方案
#1
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;
}
Pass as encode argument "UTF-8"
传递为编码参数“UTF-8”
#2
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);
Also, you might need to put charsets.jar on your classpath to support the TIS620 encoding.
此外,您可能需要在类路径上放置charsets.jar以支持TIS620编码。
#1
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;
}
Pass as encode argument "UTF-8"
传递为编码参数“UTF-8”
#2
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);
Also, you might need to put charsets.jar on your classpath to support the TIS620 encoding.
此外,您可能需要在类路径上放置charsets.jar以支持TIS620编码。