//一个将中文字转成unicode码的小程序//其中,两个变量需要修改一下。//a1.“java_bin_path”:jdk的bin目录;//a2.“source_file”:要转换的中文所在的文本文件。//生成的字符串没有换行符,请自行加上 /r 来换行package tool;

import java.io.IOException;import java.io.InputStreamReader;import java.io.UnsupportedEncodingException;

public class ChineseToUnicode {static String java_bin_path = "D://Program Files//Java//jdk1.5.0_04//bin";// 存放中文的文本文件static String source_file = "E://2.txt";

public static void main(String[] args) {String result = getUnicodeString(source_file);System.out.println(result);}

private static String getUnicodeString(String destFileName) {StringBuffer tempSb = new StringBuffer();try {Process p = Runtime.getRuntime().exec(java_bin_path+ "//native2ascii.exe " + destFileName);InputStreamReader child_in = new InputStreamReader(p.getInputStream());int c;while ((c = child_in.read()) != -1) {tempSb.append((char)c);}} catch (UnsupportedEncodingException e) {e.printStackTrace();} catch (IOException ex) {ex.printStackTrace();}

return tempSb.toString();}}

TAG标签: 微信小程序中文编码

http://www.xiaochengxub.com/read-103403.html