\u2605 ★
public static String utf8ToUnicode(String str) {
char[] myBuffer = str.toCharArray();
StringBuffer sb = new StringBuffer();
for (int i = 0; i < str.length(); i++) {
UnicodeBlock ub = UnicodeBlock.of(myBuffer[i]);
if(ub == UnicodeBlock.BASIC_LATIN){
//英文及数字等
sb.append(myBuffer[i]);
}else if(ub == UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS){
//全角半角字符
int j = (int) myBuffer[i] - 65248;
sb.append((char)j);
}else{
//汉字
short s = (short) myBuffer[i];
String hexS = Integer.toHexString(s);
String unicode = "\\" + 'u' + hexS;
sb.append(unicode.toLowerCase());
}
}
return sb.toString();
}
项目里面的么?那就在项目上右键选最下面那个propertis 然后选Resource 有个text encoding。。。选你要的编码方式么。
new String(new String("中国").getBytes(),"GBK")