java屬性文件讀取,屬性修改


/**
 * 屬性文件讀取
 * @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());
        
    }
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM