Android Studio中使用properties配置文件出现中文乱码问题

来源:互联网 发布:public c语言 编辑:程序博客网 时间:2024/05/17 04:29

今天在Android studio中使用properties配置文件时,遇到了一个问题我在main/assets/下建了一个.properties文件并指定了键值对(例如:hh=你好啊)然后读取配置文件

String url = null;Properties properties = new Properties();
try {    properties.load(c.getAssets().open("message.properties"));    url = properties.getProperty(s);} catch (Exception e) {    e.printStackTrace();}
在修改.properties文件编码格式前得到的结果是乱码的,通过网上查找找到了解决的办法(连接:http://blog.csdn.net/gc_gongchao/article/details/48266143

开发工具是Eclipse:把Properties里的编码改成GBK就可以了。

开发工具是是Android Studio:File > Settings > Editor > File Encodings 里Project Encoding(如果右下角<Transparent native-to-ascii conversion >为打对勾,则需要勾选上)

如果不想在文件中写中文可以使用native2ascii工具,将中文转成Unicode,以上的操作也就不需要了,读取出来的value自动就会转成中文


原创粉丝点击