Unicode转中文
String unicode = "\u6211\u7231\u7956\u56fd.mp3";
String result = new String(unicode.getBytes("UTF-8"), "UTF-8");
String result = new String(unicode.getBytes("UTF-8"), "UTF-8");
System.out.println(result);
结果:
我爱祖国
中文转Unicode
String chinese = "我爱祖国";
StringBuffer unicode = new StringBuffer();
for (int i = 0; i < chinese.length(); i++) {
Character character = chinese.charAt(i);
unicode.append("\\u" + Integer.toHexString(character));
}
StringBuffer unicode = new StringBuffer();
for (int i = 0; i < chinese.length(); i++) {
Character character = chinese.charAt(i);
unicode.append("\\u" + Integer.toHexString(character));
}
System.out.println(unicode.toString());
结果:
\u6211\u7231\u7956\u56fd