properties 文件的中文转ASCII
举例:1.转换一行中文文字进入jdk的bin目录,双击native2ascii.exe,输入“你好”,【回车】,屏幕上显示/u4f60/u597d2.转换一个文件cmd命令行中执行(注意配置好path环境变量)d:/>native2acsii aa.properties bb.properties如此一来就aa.properties 中的中文字符转换后保存进bb.properties 文件中。注意如果其中含有英文字符,则原样输出。
三.eclipse插件
如果是MyEclipse,安装插件方式如下:安装步骤:1、展开Eclipse的Help菜单,将鼠标移到Software Update子项,在出现的子菜单中点击Find and Install;2、在Install/Update对话框中选择Search for new features to install,点击Next;3、在Install对话框中点击New Remote Site;4、在New Update Site对话框的Name填入任意字符串中文也可以,在URL中填入http://propedit.sourceforge.jp/eclipse/updates/;然后可能需要先点击finish,不过依然会出现后面的部分(根据版本的不同而定)5、在Site to include to search列表中,除上一步加入的site外的其它选项去掉,点击Finsih;6、在弹出的Updates对话框中的Select the features to install列表中将所有结尾为“3.1.x”的选项去掉(适用于Eclipse 3.2版本的朋友);7、点击Finish关闭对话框;8、在下载后,同意安装,再按提示重启Eclipse,在工具条看到形似vi的按钮表示安装成功,插件可用。此时,Eclpise中所有properties文件的文件名前有绿色的P的图标作为标识。9、properties文件使用PropertiesEditor(右键,openwith,一般来说安装插件后默认就会使用这个编辑器)打开,输入中文,编辑器会自动将其转换为ascii码如果是Eclipse,展开help,选择Install new software,add,输入地址,确定后eclipse会进行自动搜索,不过安装插件时会出现无法安装的情况,此时可以下载我提供的安装包,下载地址 :http://download.csdn.net/source/1488797可以直接将插件包解压后的features和plugins两个文件夹复制到eclipse的home目录下,重启eclipse即可。
public class Ascii2Native {
public static void main(String[] args) { File f=new
File("E://workspaces//cas_workspace//CASServer//src//messages_zh_CN.properties");
if (f.exists() && f.isFile()) {
// convert param-file
BufferedReader br = null;
String line;
try {
br = new BufferedReader(new InputStreamReader(new FileInputStream(f), "JISAutoDetect"));
while ((line = br.readLine()) != null) {
System.out.println(ascii2native(line));
}
} catch (FileNotFoundException e) {
System.err.println("file not found - " + f);
} catch (IOException e) {
System.err.println("read error - " + f);
} finally {
try {
if (br != null)
br.close();
} catch (Exception e) {
}
}
} else {
// // convert param-data
// System.out.print(ascii2native(args[i]));
// if (i + 1 < args.length)
System.out.print("wen");
}
} public static String ascii2native(String str) {
String hex = "0123456789ABCDEF";
StringBuffer buf = new StringBuffer();
int ptn = 0;
for (int i = 0; i < str.length(); i++) {
char c = str.charAt(i);
if (c == '//' && i + 1 <= str.length() && str.charAt(i + 1) == '//') {
buf.append("////");
i += 1;
} else if (c == '//' && i + 6 <= str.length() && str.charAt(i + 1) == 'u') {
String sub = str.substring(i + 2, i + 6).toUpperCase();
int i0 = hex.indexOf(sub.charAt(0));
int i1 = hex.indexOf(sub.charAt(1));
int i2 = hex.indexOf(sub.charAt(2));
int i3 = hex.indexOf(sub.charAt(3));
if (i0 < 0 || i1 < 0 || i2 < 0 || i3 < 0) {
buf.append("//u");
i += 1;
} else {
byte[] data = new byte[2];
data[0] = i2b(i1 + i0 * 16);
data[1] = i2b(i3 + i2 * 16);
try {
buf.append(new String(data, "UTF-16BE").toString());
} catch (Exception ex) {
buf.append("//u" + sub);
}
i += 5;
}
} else {
buf.append(c);
}
}
return buf.toString();
} private static byte i2b(int i) {
return (byte) ((i > 127) ? i - 256 : i);
}
}
ps:最近发现了一个更好用的插件,可以同时编辑一组properties文件,http://www.guh-software.de/jinto_en.html,恩好东西。
properties 文件的中文转ASCII的更多相关文章
- properties文件中中文不能显示或者中文乱码
1.properties 文件中文乱码问题 鼠标“右击”文件 => Resource => Text file encoding => UTF-8 2.properties 文件解析 ...
- springBoot使用@Value标签读取*.properties文件的中文乱码问题
上次我碰到获取properties文件中的中文出现乱码问题. 查了下资料,原来properties默认的字符编码格式为asci码,所以我们要对字符编码进行转换成UTF-8格式 原先代码:@Proper ...
- Eclipse中properties文件,中文只显示Unicode问题(Properties Editor)
我们常常在properties文件中添加中文注释,而properties文件的中文需用unicode表示, 使用eclipse默认的properties文件编辑器查看显示中文为乱码. 即便修改prop ...
- 读取Properties文件以及中文乱码问题
在java类中常见的读取Properties文件方式,是使用Properties.load(inputStream);的方式但是常常出现中文乱码问题,这就很尴尬了 public synchronize ...
- Eclipse中 properties 文件中 中文乱码
在.properties文件写注释时,发现中文乱码了,由于之前在idea中有见设置.properties文件的编码类型,便找了找乱码原因 在中文操作系统中,Eclipse中的Java类型文件的编码的默 ...
- spring使用@Value标签读取.properties文件的中文乱码问题的解决
最近测试某个老系统的时候,启动的时候发@Value注入的中文是乱码,文件使用GBK/UTF-8的时候均会出现乱码问题,但是spring配置文件里面注入的占位符并没有这个问题,bean文件设置了file ...
- ResourceBundle (读取properties文件及中文乱码解决方法)
原文:http://blog.csdn.net/joecheungdishuiya/article/details/6304993 public class test { static Resourc ...
- IntelliJ IDEA设置properties文件显示中文
配置这里: 注意:上面是Default Settings,还需要在Settings中设置成上面一样的.
- 设置IDEA中properties文件显示中文
路径: File - Setting - Editor - Code Style - File Encodings
随机推荐
- 顺序队列之C++实现
下面介绍下用C++实现的顺序队列,在VC6下调试通过. 1.文件组织形式 2.sq.h顺序队列类的说明 #ifndef _SQ_H_ #define _SQ_H_ typedef int dataTy ...
- uva-11995 - I Can Guess the Data Structure!(栈,优先队列,队列,水题)
11995 - I Can Guess the Data Structure! There is a bag-like data structure, supporting two operation ...
- 正确的lnamp支持SSI的方法!即支持SHTML和include调用!
正确的lnamp支持SSI的方法!即支持SHTML和include调用! 个地方:一个是apache和nginx里的conf文件 第一步:修改apache里的httpd.conf文件 查找:AddTy ...
- hdu 1875 畅通project再续
链接:hdu 1875 输入n个岛的坐标,已知修桥100元/米,若能n个岛连通.输出最小费用,否则输出"oh!" 限制条件:2个小岛之间的距离不能小于10米,也不能大于1000米 ...
- 密钥登录linux
一.linux 主机A登录linux主机B 在/etc/hosts文件下加入:(做硬解析) 192.168.1.60 u60 #设置u60为主机名 在节点A上创建RSA秘钥:(A上生成A主机密钥) # ...
- PHP - 继承 - 子类使用父类方法
<?php class ShopProduct { private $FirstName; private $LastName; private $Title; private $Price; ...
- IDEA 中使用Maven Compile 找不到本地 Jar
本文地址:http://www.cnblogs.com/duwei/p/4656410.html 在IDEA 的子 Maven Module 中使用 compile 进行编译, 一开始提示从私有远程仓 ...
- shiro权限框架
权限的组成部分:用户 资源 角色 权限 数据库关系表设计是根据自己项目需求设计的 account表role表(id,rolename)account_role(id,aid,rid)permissio ...
- linux stat系统调用,获取文件信息。
stat 函数原型: int stat(const char *path, struct stat *buf); struct stat 说明 struct stat { mode_t st_mode ...
- UNIX网络编程 卷2:进程间通信
这篇是计算机类的优质预售推荐>>>><UNIX网络编程 卷2:进程间通信(第2版)> UNIX和网络专家W. Richard Stevens的传世之作 编辑推荐 两 ...