public class
Properties
extends Hashtable <K, V>
A Properties
object is a Hashtable
where the keys and values must be String
s . Each property can have a default Properties
list which specifies the default values to be used when a given key is not found in this Properties
instance.
//装载,读取数据
private void load() {
Properties properties=new Properties();
try {
FileInputStream stream=this.openFileInput("music.cfg");
} catch (FileNotFoundException e) {
return;
}catch(IOException e)
{
return;
}
//保存数据
boolean save() {
Properties properties=new Properties();
//将数据打包成Properties
properties.put("bmusic", String.valueOf(mbMusic));
try {
FileOutputStream stream=this.openFileOutput("music.cfg", Context.MODE_WORLD_WRITEABLE);// hashtable结构
//将打包好的数据写入文件中
properties.store(stream, "");
}catch(FileNotFoundException e)
{
return false;
}
catch (IOException e) {
return false;
}
return true;
}