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; }