android存储数据的方式3种

来源:互联网 发布:dive to blue动作数据 编辑:程序博客网 时间:2024/05/02 02:28

1:通过新建data/data下面创建文件,里面创建Key=Value来保存

     保存数据

public boolean saveFile(){    Properties properties = new Properties();    properties.put("musicFlag", String.valueOf(boolFlag));        try{    FileOutputStream outStream = this.openFileOutput("music.cfg",Context.MODE_WORLD_WRITEABLE);    properties.store(outStream,"");        }catch(Exception e){    e.printStackTrace();    return false;    }        return true;    }




读取数据

    public boolean loadFile(){    Properties properties = new Properties();        try{    FileInputStream inStream = this.openFileInput("music.cfg");    properties.load(inStream);    }catch(Exception e){    e.printStackTrace();    return false;    }    Log.v("TAG","out数据是:"+properties.get("musicFlag").toString());        boolFlag = Boolean.valueOf(properties.get("musicFlag").toString());           return true;    }


	
				
		
原创粉丝点击