方法1   properties文件的格式一般为:

ROOT=http://localhost:8080/BNCAR2/
ROOTPATH=E:/ws2/BNCAR2/rel/ MALL_PARTS_PATH=mall.jsp?rowid=0&typeFlag=0&pid=32
MALL_AFFIX_PATH=mall.jsp?rowid=0&typeFlag=1&pid=74 MALL_TYPE_TAG1=保养套装
MALL_TYPE_TAG2=系统养护
MALL_TYPE_TAG3=轮胎轮毂 NETWORK_TAG1=上海
NETWORK_TAG2=江苏

以上为保存UTF-8格式,使用UltraEdit编辑,避免出现空格导致转码错误。(在文本编辑器中有时候空格看不出来,这就是看似中文对了,实际转码会存在非法字符的原因了~!!)
java中获取配件文件信息,PropUtil.java

static Properties config = null;
static String filename = PropUtil.class.getClassLoader().getResource("bn-context.properties").getFile();
static Logger log = Logger.getLogger(PropUtil.class); public PropUtil() {
super();
config = getPropUtil();
} public static Properties getPropUtil() {
config = new Properties();
InputStream is = null;
try {
//ln("初始化config对象!");
is = PropUtil.class.getClassLoader().getResourceAsStream(
"bn-context-test.properties");
config.load(is);
} catch (IOException e) {
e.printStackTrace();
} finally {// 关闭资源
if (is != null) {
try {
is.close();
} catch (IOException e) {
}
}
}
return config;
} public static String getParameter(String key) {
if(config == null){
config = getPropUtil();
}
String value = config.getProperty(key);
// 编码转换,从ISO8859-1转向指定编码 try {
if(value != null){
value = new String(value.getBytes("ISO8859-1"), "UTF-8");
}
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} return value;
} public static void setParameter(String key,String value) {
if(config == null){
config = getPropUtil();
}
config.setProperty(key, value);
}

方法2  用UltraEdit编辑器,编写中文配置文件bn-context-test.properties,在保存后再点击另存为,文件名为prop.properties,编码选择unicode ascii就可以了。

ROOT=http://localhost:8080/BNCAR2/
ROOTPATH=E:/ws2/BNCAR2/rel/ MALL_PARTS_PATH=mall.jsp?rowid=0&typeFlag=0&pid=32
MALL_AFFIX_PATH=mall.jsp?rowid=0&typeFlag=1&pid=74 MALL_TYPE_TAG1=\u4FDD\u517B\u5957\u88C5
MALL_TYPE_TAG2=\u7CFB\u7EDF\u517B\u62A4
MALL_TYPE_TAG3=\u8F6E\u80CE\u8F6E\u6BC2 NETWORK_TAG1=\u4E0A\u6D77
NETWORK_TAG2=\u6C5F\u82CF

如果这种情况,以上java代码就不需要转码那部分代码,注释掉。

        // 编码转换,从ISO8859-1转向指定编码

//        try {
// if(value != null){
// value = new String(value.getBytes("ISO8859-1"), "UTF-8");
// }
// } catch (UnsupportedEncodingException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }

properties配置文件中文乱码解决方法的更多相关文章

  1. Eclipse的properties文件中文乱码解决方法

    转自:http://jingyan.baidu.com/article/ed2a5d1f3381d709f6be17f8.html 打开Myeclipse,找到window这一栏,点击Preferen ...

  2. eclipse下properties配置文件中文乱码解决

    properties文件常带有中文注释,eclipse显示是乱码. 安装插件(properties editor)可以解决properties配置文件乱码的问题. 菜单 : Help->Ecli ...

  3. Java 前台后台数据传递、中文乱码解决方法

    1.向前台传递数据;2.向后台传递数据;3.ajax post 提交数据到服务端时中文乱码解决方法;4.数组类型参数传递; 1.向前台传递数据:1.1 字符串数据传递:  这种方式只是单一的向前台传递 ...

  4. centos7 中文乱码解决方法

    centos7 中文乱码解决方法 标签(空格分隔): centos7 1.查看安装中文包: 查看系统是否安装中文语言包 (列出所有可用的公共语言环境的名称,包含有zh_CN) # locale -a ...

  5. php mysql 中文乱码解决方法

    本文章向码农们介绍php mysql 中文乱码解决方法,对码农们非常实用,需要的码农可以参考一下. 从MySQL 4.1开始引入多语言的支持,但是用PHP插入的中文会出现乱码.无论用什么编码也不行 解 ...

  6. jquery的ajax()函数传值中文乱码解决方法介绍

    jquery的ajax()函数传值中文乱码解决方法介绍,需要的朋友可以参考下 代码如下: $.ajax({ dataType : ‘json', type : ‘POST', url : ‘http: ...

  7. [转]mysql导入导出数据中文乱码解决方法小结

    本文章总结了mysql导入导出数据中文乱码解决方法,出现中文乱码一般情况是导入导入时编码的设置问题,我们只要把编码调整一致即可解决此方法,下面是搜索到的一些方法总结,方便需要的朋友. linux系统中 ...

  8. Zxing中文乱码解决方法

    Zxing中文乱码解决方法总结 尝试过非常多方法  最后发现此方法解决的乱码最多....... 在百度搜索二维码图片 经过前2页的測试  除开一张图之外  其余都能扫描出结果 假设大家有更好的解决方法 ...

  9. unity3d 中文乱码解决方法——cs代码文件格式批量转化UTF8

    在Unity3d中经常会碰到中文乱码的问题,比如代码中的[AddComponentMenu("GameDef/AI/战机AI")],注释,中文文本等等 其原因在于,unity本身是 ...

随机推荐

  1. Visual Assist X 10.6.1837完美破解版(带VS2010破解)

    Visual Assist X 10.6.1837完美破解版(带VS2010破解) 实用软件, 资源分享Add comments 八102011 转载自:http://www.blog.namind. ...

  2. [GeekBand] STL与泛型编程(1)

    在C++语法的学习过程中,我们已经对模板有了基本的了解.泛型编程就是以模板为工具的.泛化的编程思想.本篇文章介绍了一些在之前的文章中没有涉及到的一些模板知识.泛型编程知识和几种容器.关于模板的一些重复 ...

  3. 04_例子讲解:rlViewDemo.exe

    参考资料:http://www.roboticslibrary.org/tutorials/first-steps-windows 使用rlViewDemo对应的快捷方式启动程序,可以看到如下界面: ...

  4. What are Upgrade, Product and Package Codes used for? By pusu

    Following content is reprinted from here, please go to the original website for more information. Au ...

  5. An Easy Task

    An Easy Task Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total ...

  6. struts2使用struts2-bootstrap-plugin插件

    1.下载插件 http://code.google.com/p/struts2-bootstrap/ 2.添加maven依赖 <dependency> <groupId>com ...

  7. KnockoutJS(1)-数据模型

    前言 说到数据模型(ViewModel),就不得不提到MVVM模式,接触过WPF和Silverlight的人应该对这个模式比较熟悉. 不熟悉也没多大关系,因为KnockoutJS的使用相对简单. MV ...

  8. 玩转Slot Machine

    最近在做一个有关Slot  Machine小游戏的开发,其中遇到了不少的坑,现将个人遇到的问题总结如下,希望今后对大家开发的过程中有所的帮助. 这个项目是部署到微信朋友圈广告的,两天时间,PV就有14 ...

  9. html实现层叠加

    <div id="canvasesdiv" style="position:relative; width:400px; height:300px"> ...

  10. Ajax 之【文件上传】

    // 前台 var formData = new FormData(); var file = document.getElementById('myFile').files[0]; formData ...