/** * 属性文件读取 * @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()); } }
时间: 2024-10-10 10:31:47