public class Test {
public static String convertGBK2UTF8(String str) {
String tmp;
StringBuffer sb = new StringBuffer(1000);
char c;
int i, j;
sb.setLength(0);
for (i = 0; i < str.length(); i++) {
c = str.charAt(i);
if (c > 255) {
sb.append("\\u");
j = (c >>> 8);
tmp = Integer.toHexString(j);
if (tmp.length() == 1)
sb.append("0");
sb.append(tmp);
j = (c & 0xFF);
tmp = Integer.toHexString(j);
if (tmp.length() == 1)
sb.append("0");
sb.append(tmp);
} else {
sb.append(c);
}
}
return (new String(sb));
}
public static void main(String[] args) {
System.out.println( Test.convertGBK2UTF8("这是JAVAEE & JIVE 组织 !"));
}
}
结果:\u8fd9\u662fJAVAEE & JIVE \u7ec4\u7ec7 \uff01
posted on 2008-01-13 14:17
Crying 阅读(991)
评论(0) 编辑 收藏 所属分类:
JAVA基础