Runtime rt = Runtime.getRuntime();
Process pro = rt.exec("cmd /c native2ascii.exe -reverse C:\\temp\\to.txt > C:\\temp\\from.txt");
pro.waitFor();
/**
* unicode转中文
* @param str 要转的Unicode字符串
* @return String 转化后的字符串
* @throws IOException
* @throws InterruptedException
*/
private String unicodeToChinese(String strs) throws IOException, InterruptedException
{
File file = new File("C:\\temp");
if (!file.exists())
{
file.mkdir();
}
File fileFrom = new File(file,"from.txt");
File toFrom = new File(file,"to.txt");
if (!fileFrom.exists())
{
fileFrom.createNewFile();
}
if (!toFrom.exists())
{
toFrom.createNewFile();
}
BufferedWriter bw = new BufferedWriter(new FileWriter(toFrom));
bw.write(strs);
bw.close();
//运行系统的命令
Runtime rt = Runtime.getRuntime();
Process pro = rt.exec("cmd /c native2ascii.exe -reverse C:\\temp\\to.txt > C:\\temp\\from.txt");
pro.waitFor();
//toFrom.delete();
BufferedReader br = new BufferedReader(new FileReader(fileFrom));
StringBuffer sb = new StringBuffer();
String readStr = br.readLine();
while (null != readStr)
{
sb.append(readStr);
sb.append("\n");
readStr = br.readLine();
}
br.close();
//System.out.println(sb.toString());
//fileFrom.delete();
return sb.toString();
}
/**
* 中文转unicode
* @param str
* @return String 反回unicode编码
*/
private String chinaToUnicode(String str)
{
StringBuffer result = new StringBuffer();
for (int i = 0; i < str.length(); i++)
{
int chr1 = (char) str.charAt(i);
//汉字范围 \u4e00-\u9fa5 (中文)
if(chr1 >= 19968 && chr1 <= 171941)
{
result.append("\\u" + Integer.toHexString(chr1));
}
else
{
result.append(str.charAt(i));
}
}
return result.toString();
}