自己手里有一部分Unicode,都是文本转译过来的,没有\u 的前缀,于是想通过下面的代码给重新译成文字,结果大部分都正常,只有少数出现code不能转换,不知道是正则识别的问题还是其他地方有问题,单独把那几个没识别的给挑出来,用DeCode却能正常译出。
比如“C++”译出来的大多是004。b         “电器”译出来的是7单668public static String DeCode(String str){
Pattern pattern = Pattern.compile("(([0-9a-f]{4}))");
Matcher matcher = pattern.matcher(str);

char ch;
while(matcher.find()){
ch = (char)Integer.parseInt(matcher.group(0), 16);
str = str.replace(matcher.group(0), ch + "");
}

return str;
} String strf = DeCode(str);

File outfile = new File("e:/output.txt");

try{
FileWriter fw = new FileWriter(outfile);
BufferedWriter bw = new BufferedWriter(fw);
bw.write(strf);
bw.newLine();
bw.close();
fw.close();
}
catch(IOException e){
e.printStackTrace();
}
unicodejava