Java读取properties中文乱码

Java读取properties中文乱码

右击该properties文件–properties–Resource–Text file encoding,选中other,选择其它编码方式,如UTF-8或GBK,这样就能在properties里面输入中文,而不会自动转成Unicode了。

另外,其实如果key value是中文,也不一定读不出来。比如如下的情况,打开文件流时选择了正确的编码方式,这样用properties的load的方法可以加载中文的。(但有的情况下你选择不了编码方式自然就有问题了)。

BufferedReader br = null;
Properties datas = new Properties();
br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("data.properties")), "GBK"));
datas.load(br);

你可能感兴趣的:(Java,ssm)