您的位置:首页 > 编程语言 > Java开发

java属性文件读取,属性修改

2014-12-08 13:52 309 查看
/**
* 属性文件读取
* @author bestmata
*
*/
public class CommUtil {

private static Logger logger=Logger.getLogger(CommUtil.class);

private  Properties getAttionReplyPro(){
try {
InputStream in=CommUtil.class.getResourceAsStream("attionReply.properties");
Properties p=new Properties();
p.load(in);
in.close();
return p;
} catch (Exception e) {
logger.error(e);
}
return null;

}

//获取关注的标示
public  String getAttionFlag(){
Properties p=getAttionReplyPro();
String attionFlag=p.getProperty("attionFlag");
return attionFlag;
}

//设置attionFlag的值
public  void setAttionFlag(String flag){
try {
Properties p=getAttionReplyPro();
p.setProperty("attionFlag", flag);
OutputStream out=new FileOutputStream(new File(CommUtil.class.getResource("attionReply.properties").toURI()));
p.store(out, "");
out.flush();
out.close();
} catch (Exception e) {
logger.error(e);
}

}

public static void main(String[] args) {
CommUtil a=new CommUtil();
a.setAttionFlag("fag4");
System.out.println(a.getAttionFlag());

}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: