Repository navigation
Expand file tree
/
Copy pathUtils.java
More file actions
51 lines (45 loc) · 1.57 KB
/
Copy pathUtils.java
File metadata and controls
51 lines (45 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import java.io.IOException;
import java.util.Properties;
/**
* Created by geekgao on 16-1-29.
*/
public class Utils {
private static Properties config = new Properties();
static {
try {
config.load(Utils.class.getResourceAsStream("/config.properties"));
} catch (IOException e) {
e.printStackTrace();
}
}
public static String getRoomId() throws IOException {
return config.getProperty("roomId");
}
/**
* 将包含unicode的字符串 转 中文字符串
* 将每个unicode编码计算出其值,再强转成char类型,然后将这个字符存储到字符串中
*/
public static String unicode2String(String str) {
StringBuilder result = new StringBuilder();
for (int i = 0;i < str.length();) {
if (str.charAt(i) == '\\' && str.charAt(i + 1) == 'u') {
String unicode = str.substring(i + 2, i + 6);
//确定是unicode编码
if (unicode.matches("[0-9a-fA-F]{4}")) {
//将得到的数值按照16进制解析为十进制整数,再強转为字符
char ch = (char) Integer.parseInt(unicode, 16);
//用得到的字符替换编码表达式
result.append(ch);
i += 6;
} else {
result.append("\\u");
i += 2;
}
} else {
result.append(str.charAt(i));
i++;
}
}
return result.toString();
}
}