拼接两个Properties文件
一个英文一个中文翻译
中文转码为Unicode
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
public class ParseProperties
{
public static void main(String args[]) throws FileNotFoundException,
IOException
{
Properties resource = new Properties();
Properties translate = new Properties();
resource.load(new FileInputStream(new File(
"./resource/resource.properties")));
translate.load(new FileInputStream(new File(
"./resource/translate2.properties")));
BufferedReader reader = new BufferedReader(new FileReader(
"./resource/resource.properties"));
BufferedWriter writer = new BufferedWriter(new FileWriter(
"./resource/target.properties"));
BufferedReader reader2 = new BufferedReader(new FileReader(
"./resource/translate2.properties"));
Map<String, String> map = new HashMap<String, String>();
String tempStr;
while ((tempStr = reader2.readLine()) != null)
{
if (tempStr.contains("="))
{
String key = tempStr.substring(0, tempStr.indexOf("=")).trim();
String value = tempStr.replace(tempStr.substring(0,
tempStr.indexOf("=") + 1),
"").trim();
System.out.println(toUnicode(value));
map.put(key, toUnicode(value));
}
}
while (null != (tempStr = reader.readLine()))
{
if (tempStr.contains("="))
{
String key = tempStr.substring(0, tempStr.indexOf("=")).trim();
tempStr = " " + key + " = en-us#"
+ resource.getProperty(key) + "@zh-cn#" + map.get(key);
}
writer.write(tempStr);
writer.newLine();
}
writer.flush();
writer.close();
}
public static String toUnicode(String str)
{
StringBuffer sb = new StringBuffer();
for (int i = 0; i < str.length(); i++)
{
char c = str.charAt(i);
if (isSpeChar_zh_cn(c))
{
sb.append("\\u");
sb.append(Integer.toHexString(str.charAt(i)));
}
else
{
sb.append(c);
}
}
return sb.toString();
}
/**
* 判断指定的实体是否属于中文
*/
private static boolean isSpeChar_zh_cn(int nEntity)
{
return ((nEntity >= 0x4E00 && nEntity <= 0x9FA5)
|| (nEntity >= 0xFF01 && nEntity <= 0xFF5E)
|| (nEntity >= 0xFF61 && nEntity <= 0xFF9F)
|| (nEntity >= 0xFFE0 && nEntity <= 0xFFE6)
|| (nEntity >= 0xFFE8 && nEntity <= 0xFFEE)
|| (nEntity >= 0x3000 && nEntity <= 0x3029)
|| (nEntity >= 0x3030 && nEntity <= 0x3037) || nEntity == 8220 //全角左双引号
|| nEntity == 8221 //全角右双引号
|| nEntity == 8216 //全角左单引号
|| nEntity == 8217 //全角右单引号
|| nEntity == 9678 //◎
|| nEntity == 8230 //…
|| nEntity == 8251 //※
);
}
}
分享到:
相关推荐
主要介绍了Python实现读取Properties配置文件的方法,结合实例形式分析了Python读取Properties配置文件类的定义与使用相关操作技巧,需要的朋友可以参考下
而且在java 中有 java.util.Properties 这个类,可以很方便的处理properties 文件, 在python 中虽然也有读取配置文件的类ConfigParser, 但如果习惯java 编程的人估计更喜欢下面这个用python 实现的读取 properties ...
python没有专门处理properties格式的包,只有处理标准的ini格式的包。所以需要自己写一个python程序来处理。不说了上程序。 这里参考前面一篇://www.jb51.net/article/137390.htm 主要在前文的基础上,增加key.key....
进行properties文件的批量处理工具,能够用来改动部分参数而进行的文本提取修改工具。
properties与json互相装换, 主要是为了将以前的properties配置存入XDiamond配置中心, 里边需要的json格式需要处理. 此文件可以批量的将properties转换成json字符串并输出为txt文件. 使用:PropToJson.toJSONString...
这是一个简单的案例用来实现Spring中jdbc.properties属性文件进行密文处理,代码中的学生实体自己根据需要在数据库中进行创建
ava中有个比较重要的类Properties(Java.util.Properties),主要用于读取Java的配置文件,各种语言都有自己所支持的配置文件,配置文件中很多变量是经常改变的,这样做也是为了方便用户,让用户能够脱离程序本身去...
如果经常使用Struts,并做过国际化操作的人来说,对于中文资源文件的处理应该不会感到陌生的。比如下面两个文件,一个是英文的,一个是中文的。对于英文的,一切照常;对于中文的,一般需要用JDK的native2ascii工具...
解决properties乱码 j2ee只要将该文件复制到你的文件中输入要处理的的文件的路径和要输入的内容运行就可以解决中文乱码问题
获取properties文件中设定好key值的value值
读资源文件的处理,保存增、删、改、查操作
这里面有详细的处理maven项目中resources目录下的资源文件,方便快捷的得到或设置资源文件中的内容,本人亲测,里面还有示例
郭进guo jin博士论文,关于自然语言处理
NULL 博文链接:https://rmn190.iteye.com/blog/1134249
在java中,类Properties用于处理配置文件相关的读取。下面是一个关于根据所提供的键获取值的示例。 public static String getvalue(String key) { Properties p=new Properties(); FileInputStream fis; String...
PostCSS自定义属性 使您可以按照规范在CSS中使用自。 :root { --color : red;... const postcssCustomProperties = require ( 'postcss-custom-properties' ) ; postcssCustomProperties . process ( YOUR_
视频直播系统 2018第五章 自定义播放器提交Properties处理
本文实例讲述了ajax读取properties资源文件数据的方法。分享给大家供大家参考...js调用ajax处理代码: $.ajax({ type:'POST', dataType:'json', url:'/jeecms/jeecms/ajax/cms/getResourceBundle.do', async:fals
概述请运行git pull --tags更新标签。 请参阅原因。 properties是用于读取和写入属性文件的Go库。... 默认值已从panic更改为log.Fatal但这是可配置的,并且可以提供自定义错误处理功能。 有关详细信息,请参见包装
hanlp.properties,HanLP是由一系列模型与算法组成的Java工具包,此文件为hanlp的配置文件