properties属性文件

我要配置属性文件,key值是中文的
我使用的是properties配置文件,key值为中文,使用InputStream流读入后key值都乱码,有什么方法可以解决?

还有其他方式来读取中文的key值吗?

Java直接读取properties文件时,中文会是乱码,这时可以用Java\jdk1.x.x\bin\native2ascii.exe工具。
例如,把f1.properties转换成f2.properties。

在cmd的当前目录下输入:
native2ascii -encoding gbk f1.properties f2.properties

转换前f1.properties:
#编号=描述

cn=中国

转换后f2.properties:
#\u7f16\u53f7=\u63cf\u8ff0

cn=\u4e2d\u56fd

这样Java程序就可以正确识别中文了!
Java代码
Properties prop=new Properties();

InputStream inputStream=new FileInputStream("E:\f2.properties");

prop.load(inputStream);

String title=prop.getProperty("cn");

System.out.println(title);

转换前运行结果:控制台代码
???ú

转换后运行结果:控制台代码
中国

别处看的,你可以试试看