Code example for Properties

Methods: load, putAll, store

0
        return (props != null) ? props.getProperty(key) : null;
    } 
 
    public Properties get() {
        FileInputStream fis = null;
        Properties props = new Properties();
        try { 
            // ¶ÁÈ¡filesĿ¼ÏµÄconfig 
            // fis = activity.openFileInput(APP_CONFIG); 
 
            // ¶ÁÈ¡app_configĿ¼ÏµÄconfig 
            File dirConf = mContext.getDir(APP_CONFIG, Context.MODE_PRIVATE);
            fis = new FileInputStream(dirConf.getPath() + File.separator
                    + APP_CONFIG);
 
            props.load(fis);
        } catch (Exception e) {
        } finally { 
            try { 
                fis.close();
            } catch (Exception e) {
            } 
        } 
        return props;
    } 
 
    private void setProps(Properties p) {
        FileOutputStream fos = null;
        try { 
            // °Ñconfig½¨ÔÚfilesĿ¼Ï 
            // fos = activity.openFileOutput(APP_CONFIG, Context.MODE_PRIVATE); 
 
            // °Ñconfig½¨ÔÚ(×Ô¶¨Òå)app_configµÄĿ¼Ï 
            File dirConf = mContext.getDir(APP_CONFIG, Context.MODE_PRIVATE);
            File conf = new File(dirConf, APP_CONFIG);
            fos = new FileOutputStream(conf);
 
            p.store(fos, null);
            fos.flush();
        } catch (Exception e) {
            e.printStackTrace();
        } finally { 
            try { 
                fos.close();
            } catch (Exception e) {
            } 
        } 
    } 
 
    public void set(Properties ps) {
        Properties props = get();
        props.putAll(ps);
        setProps(props);
    } 
 
    public void set(String key, String value) {
        Properties props = get();