/**
* 生成Properties文件
* @param map Properties文件的内容,键值对
* @param path Properties文件生成后存放的路径
* @param propName Properties文件的名称
* @param annotation Properties文件前面的注释
*/
public static int setprop(Map<String, String> map,String path,String propName,String annotation) {
Properties prop = new Properties();
Set keySet = map.keySet(); // key的set集合
Iterator it = keySet.iterator();
while(it.hasNext()){
Object k = it.next(); // key
Object v = map.get(k); //value
prop.put(propName+k,v);
}
try {
//保存
FileOutputStream out = new FileOutputStream(path+"//"+propName+".properties");
//为properties添加注释
prop.store(out, annotation);
out.close();
return 1;
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return 0;
}
05-08 08:43