方法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. oracle开启audit(审计)

    1.查看审计功能是否开启(本机已经开启,如果audit_sys_operations值为FALSE就是没开审计) [sql] view plaincopyprint? SQL> CONN /AS ...

  2. OC4_电子词典

    // // MyDictionary.h // OC4_电子词典 // // Created by zhangxueming on 15/6/15. // Copyright (c) 2015年 zh ...

  3. javascript笔记——js面试问题

    1:javascript中的变量提升(先使用再声明,js中的函数也存在函数提升) 2:js中的事件捕获和事件冒泡(是两个相反的过程) 3:js中的动画队列(比如animate动画没有在点击的时候阻止正 ...

  4. 添加线标注ILineElement

    private void AddLineElement(IPolyline polyline) { try { IPolyline pPolyline = polyline; IRgbColor pL ...

  5. 如何测量一个嵌入式Linux系统的功耗/power dissipation/power wastage/consumption

    参考: 1.Linux Circuit Software To Calculate Power Dissipation

  6. JAVA_SE复习(OOP1)

    面向对象编程(一) 一.继承 1. 在类图表示中,使用一个分为三块的矩形表示一个类.矩形的第一块表示类名,第二块描述这个类的属性及属性的数据类型,第三块描述这个类的操作,也就是方法以及返回类型.    ...

  7. 【转载】GDB反向调试(Reverse Debugging)

    记得刚开始学C语言的时候,用vc的F10来调试程序,经常就是一阵狂按,然后一不小心按过了.结果又得从头再来,那时候我就问我的老师,能不能倒退回去几步.我的老师很遗憾地和我说,不行,开弓没有回头箭.这句 ...

  8. JavaScript null and undefined

    http://stackoverflow.com/questions/6429225/javascript-null-or-undefined var x; x == null // true x = ...

  9. 判断IE版本的语句 [if lte IE 6]...[endif]

    <!–[if lte IE 6]>……<![endif]–>Ite:less than or equal to意思是小于或等于IE6浏览器,用于IE浏览器的条件注释,常用于CS ...

  10. aix 上搭建node.js 环境

    下载nodejs:ibm-4.4.3.0-node-v4.4.3-aix-ppc64.bin IBM已经适配最新版本的node.js  :https://developer.ibm.com/node/ ...