我现在使用以下代码,但它的性能不佳。只能转换很少的单词。
public String convert(String big5) throws java.io.UnsupportedEncodingException {
byte[] tmp = big5.getBytes( "UTF-16BE");
String result = "";
for (int i=0; i<tmp.length; i++) {
result += Integer.toHexString(((int)tmp[i]));
}
return result.toUpperCase();
}
最佳答案
这对你有用吗?
result += Integer.toHexString(((int)(tmp[i] & 0xFF)));
要将字节值视为无符号,您需要使用 0xFF 进行按位 &。
希望这有帮助。
关于Java 如何从 request.getParameter() 函数将字符串转换为 UTF-16BE?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16304530/