表单的数据全没了。
.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();
}
把
.properties
文件放在项目外边,例如/etc/my-project/my-project.properties