java读取*.properties配置文件时,中文乱码解决方法
来源:互联网 发布:flotherm软件下载 编辑:程序博客网 时间:2024/06/07 04:00
之前项目中用到的代码块(读取配置文件会乱码):
public class PropertiesConfig { private static Logger log = Logger.getLogger(PropertiesConfig.class); public PropertiesConfig() { } private static Properties props = new Properties(); static { try { props.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("propertyconfig.properties")); } catch (FileNotFoundException e) { log.error(e); } catch (IOException e) { log.error(e); } } public static String getValue(String key) { return props.getProperty(key); }}
但是当配置文件中存在如下类型的key=value时,会出现value乱码
user_name=王大力
此时读取到的“王大力“乱码,解决方法(更改静态代码块):
static { try { InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("msgconfig.properties"); BufferedReader bf = new BufferedReader(new InputStreamReader(inputStream, "UTF-8")); props.load(bf); } catch (FileNotFoundException e) { log.error(e); } catch (IOException e) { log.error(e); } }
这样读到的值不会乱码。
0 0
- Java读取properties配置文件时,中文乱码解决方法
- Java读取properties配置文件时,中文乱码解决方法 .
- java读取*.properties配置文件时,中文乱码解决方法
- Java读取properties配置文件时,中文乱码解决方法
- Java读取properties配置文件时,中文乱码解决方法
- java读取properties配置文件时中文乱码解决办法
- Android读取xxx.properties配置文件中文出现乱码解决方法
- java程序读取properties配置文件出现中文乱码
- java读取properties配置文件,并解决中文乱码
- java读取properties中文乱码
- java 读取properties 中文乱码
- java读取properties中文乱码
- Java 读取.properties中文乱码
- Java读取properties文件 中文乱码问题
- Java读取properties文件中文乱码问题解决
- Java读取properties文件中文乱码问题解决
- java读取properties文件,中文乱码处理
- Java读取properties文件中文乱码问题解决
- [UVA] 10976 Fractions Again?!
- Linux下使用nexus搭建maven私服
- cookie用法
- Android 报错android.view.WindowLeaked.....has leaked window com.android.internal.policy.
- ALTER 简单操作(mysql)
- java读取*.properties配置文件时,中文乱码解决方法
- 更改jdk配置 路径
- 在QT/QML中使用FontAwesome做图标显示
- Python包间模块的互相调用
- 启动react-native run-android找不到文件问题
- CentOS 7 下使用虚拟环境Virtualenv安装Tensorflow cpu版记录
- Examples of using minFunc
- 分类器设计之线性分类器和线性SVM(含Matlab代码)
- list排序二