1 //中文转UNICODE 2 public static String chinaToUnicode(String str) { 3 String result = ""; 4 for (int i = 0; i < str.length(); i++) { 5 int chr1 = (char) str.charAt(i); 6 if (chr1 >= 19968 && chr1 <= 171941) {// 汉字范围 \u4e00-\u9fa5 (中文) 7 result += "\\u" + Integer.toHexString(chr1); 8 } else { 9 result += str.charAt(i); 10 } 11 } 12 return result; 13 }
1 //UNICODE转中文 2 public static String unicodeToChina(String str) throws Exception{ 3 byte[] byteArr = str.getBytes("UTF-8"); 4 String chinese=new String(byteArr,"UTF-8"); 5 return chinese; 6 } 7