Unicode转中文
String unicode = "\u6211\u7231\u7956\u56fd.mp3";
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));
}
System.out.println(unicode.toString());
结果:\u6211\u7231\u7956\u56fd
版权声明:本文为博主原创文章,未经博主允许不得转载。
时间: 2024-09-30 20:55:39