首页  

Properties使用UTF8读取中文配置文件     所属分类 java 浏览量 1112
// utf8  不需要 native2ascii 转成 Unicode
		String resource = "config.properties";
		//  native2ascii 转成 Unicode
		String resourceUnicode = "config-unicode.properties";
		Properties prop=new Properties();         
		prop.load(PropertiesReadTest.class.getClassLoader().getResourceAsStream(resource));
		// 乱码
		System.out.println(prop);
		
		prop=new Properties();         
	       prop.load(PropertiesReadTest.class.getClassLoader().getResourceAsStream(resourceUnicode));
	       // 读取转码后配置文件 正常
		System.out.println(prop);
		
		prop=new Properties();         
		prop.load(new InputStreamReader(PropertiesReadTest.class.getClassLoader().getResourceAsStream(resource), "UTF-8"));
		// 使用 utf8 读取utf8 非转码配置 正常
		System.out.println(prop);



config.properties

name=cat
name1=老虎


config-unicode.properties

name=cat
name1=\u8001\u864E

上一篇     下一篇
AOP知识点

spring aop 内部方法调用拦截说明

spring aop cglib 代理类源码查看

spring5自动装配实例

eclipse异常断点设置

eclipse设置条件断点和异常断点