一个将中文字符转成unicode编码的小程序
//一个将中文字转成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();}}
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。

