如何将TIS-620字符串转换为Java中的UTF-8字符串?
答
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”
答
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在classpath支持TIS620编码。
仍然没有完全正确的工作! – user21508 2008-10-30 09:36:34