eclipse的Clean后, .properties文件被清除了,怎么办?

图片描述

表单的数据全没了。
.properties文件是放在src下的
如下是代码:

//读取
    public static Map<String,String> get() throws IOException {
        Map<String,String> propMap = new HashMap<String,String>();
        Properties prop = new Properties();
        InputStream in = new BufferedInputStream(new FileInputStream(Thread.currentThread().getContextClassLoader().getResource("base.properties").getPath()));
        prop.load(in);     ///加载属性列表
        Iterator<String> it=prop.stringPropertyNames().iterator();
        while(it.hasNext()){
            String key=it.next();
            propMap.put(key, new String(prop.getProperty(key).getBytes("ISO-8859-1"),"utf-8"));
        }
        in.close();
        
        return propMap;
    }
    //写入
    public static void save(Map<String,String> map) throws IOException {
        Properties prop = new Properties();
        FileOutputStream oFile = new FileOutputStream(Thread.currentThread().getContextClassLoader().getResource("base.properties").getPath(), false);
        Iterator<Map.Entry<String, String>> entries = map.entrySet().iterator();
        while(entries.hasNext()) {
            Map.Entry<String, String> m = entries.next();
            prop.setProperty(m.getKey(), m.getValue());
        }
        prop.store(new OutputStreamWriter(oFile, "utf-8"), "The New properties file");
        oFile.close();
    }
阅读 2.8k
1 个回答

.properties文件放在项目外边,例如/etc/my-project/my-project.properties

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