一个将中文字符转成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();
}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值