不算乱码吧,只是把中文转为了 unicode 进行存储而已

解决方案 »

  1.   

    你说的乱码是这个吗?Frequency=\u54c8\u54c8这是改不了的,除非你不用Properties类,因为在Properties类里已经写死了:    private void dumpString(StringBuilder buffer, String string, boolean key) {
            int i = 0;
            if (!key && i < string.length() && string.charAt(i) == ' ') {
                buffer.append("\\ ");
                i++;
            }        for (; i < string.length(); i++) {
                char ch = string.charAt(i);
                switch (ch) {
                case '\t':
                    buffer.append("\\t");
                    break;
                case '\n':
                    buffer.append("\\n");
                    break;
                case '\f':
                    buffer.append("\\f");
                    break;
                case '\r':
                    buffer.append("\\r");
                    break;
                default:
                    if ("\\#!=:".indexOf(ch) >= 0 || (key && ch == ' ')) {
                        buffer.append('\\');
                    }
                    if (ch >= ' ' && ch <= '~') {
                        buffer.append(ch);
                    } else {
                        String hex = Integer.toHexString(ch);
                        buffer.append("\\u");
                        for (int j = 0; j < 4 - hex.length(); j++) {
                            buffer.append("0");
                        }
                        buffer.append(hex);
                    }
                }
            }
        }
      

  2.   

    这应该对你没有影响吧,因为Properties的加载和保存都自动处理编码了。
    你是想自己解析Properties生成的文件吗?那倒不如用json作为文件格式了。
      

  3.   

    如果一定要中文的话,你就自己手动输出文件不就好了public void saveConfig(String file, Properties properties) {  
            try {  
                FileOutputStream s = new FileOutputStream(file, false);  
                BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(s, "utf-8"));
                //在这里手动遍历属性和值进行输出
                s.close();
            } catch (Exception e){  
                e.printStackTrace();  
            }  
        }但是如果这样输出的话,你再使用Properties进行读取加载,可能不能读到你想要的东西
      

  4.   


    因为这个东西要拿出来给别人用的。所以要显示中文的。
    那用json格式很方便啊。
      

  5.   


    因为这个东西要拿出来给别人用的。所以要显示中文的。
    那用json格式很方便啊。
    json写到文件里面不是a=b这种格式
      

  6.   


    因为这个东西要拿出来给别人用的。所以要显示中文的。
    那用json格式很方便啊。
    json写到文件里面不是a=b这种格式
    为什么一定要a=b的格式,直接用json就可以,现在没有那种主流语言不支持json吧。
    如果你一定要用properties的格式,那就只能自己转一下了。直接用android类库是做不了了,因为properties把代码写死了。
      

  7.   

    所谓的数据储存,读取,不过是双方相互之间规定某种特定格式的文本进行传输。不必太在意格式问题,什么gson,json,xml,都可以。只要你知道怎么解析就好了,如果你希望方便使用,不希望自己创建类进行解析生成 什么的,json,xml这种很多语言支持的自然是首选,如果你向自己使用解析,你就可以随便写了,只要自己知道怎么解析,是什么含义就好了
      

  8.   


    同样的代码,在java上,不在android上运行,拿出文档来看就不是unicode编码的。public class test123 {
    public static void main(String[] args) {
    Properties prop = new Properties();
    int issueType = 1;
    int frequency = -1;
    String description = "123131234124";
    String contactInfo = "1234567";
    prop.setProperty("IssueType", "呵呵");  
    prop.setProperty("Frequency", "12345");  
    prop.setProperty("Description", description);
    prop.setProperty("ContactInfo", contactInfo);
    saveConfig("c:/1.txt", prop); } static public void saveConfig(String file, Properties properties) {  
         try {  
         FileOutputStream s = new FileOutputStream(file, false);  
         BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(s, "utf-8"));
         properties.store(bw, "");
         s.close();
         } catch (Exception e){  
         e.printStackTrace();  
         }  
        }
    }
      

  9.   

    android和java还是不一样的,android为了很多效率以及别的因素对java本身的库函数做了很多修正的,所以使用android的java类库的时候,并不是完全和oracle的类库一样