public String utf8ToUnicode(String str) {
str = (str == null ? "" : str);
String tmp;
StringBuffer sb = new StringBuffer(1000);
char c;
int i, j;
for (i = 0; i < str.length(); i++) {
c = str.charAt(i);
sb.append("\\u");
// 取出高8位
j = (c >>> 8);
tmp = Integer.toHexString(j);
if (tmp.length() == 1)
//不足两位补0
sb.append("0");
sb.append(tmp);
// 取出低8位
j = (c & 0xFF);
tmp = Integer.toHexString(j);
if (tmp.length() == 1)
//不足两位补0
sb.append("0");
sb.append(tmp);
}
return (new String(sb));
}
public String uft8ToUnicode(String str) {
StringBuffer sb= new StringBuffer();
for (int i = 0; i < str.length(); i++) {
sb.append("\\u");
sb.append(Integer.toHexString(str.charAt(i)));
}
return sb.toString();
}
以上两种方法均为手写伪代码,实际操作还需各位稍加修改