对propertie文件输入的时候,中文注释变成编码。

public static void main(String[] args){

    try {
        //向属性文件输入
        FileOutputStream fileOutputStream =new FileOutputStream("/home/joy/桌面/a.properties",true);
        Properties properties =new Properties();
        properties.setProperty("键","值");
        String annotation = "注释";
        BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(fileOutputStream,"utf-8") );
        properties.store(bufferedWriter,annotation);
        bufferedWriter.close();
    } catch (Exception e) {
        System.out.println(e.toString());
    }
}
    
#\u6CE8\u91CA
#Fri Feb 03 19:58:24 CST 2017
键=值

这是在properties文件输出的,但是那个”注释“这个中文却变成了\u6CE8\u91CA,怎么解决。。我尝试换成String str = new Sting("注释".getBytes,"utf-8")也没能解决。
阅读 3.1k
2 个回答

这不是很正常么,你用的IDE编辑器的问题,如果是eclipse可以marketplace搜索properties相关的编辑器下载安装并用这个打开properties文件

eclipse安装属性文件读取文件插件,名字是propertiesEditor,然后选中文件,邮件open-with --------> propertiesEditor就OK了

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题