Editor edit = shared.edit();//获取编辑器
edit.putString("numberpwd",content);
edit.commit();//提交修改
例:
public static boolean write(Context context) {
// 获取SharedPreferences对象
/**
* param1: 创建的xml的名称
* param2: 该xml的访问的权限(Context去获取 mode)
*/
SharedPreferences shared = context.getSharedPreferences(Constant.PATH,
Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE);
// 获取到他的编辑器
Editor editor = shared.edit();
editor.putString("name", "zs");
editor.putInt("age", 18);
editor.putFloat("weight", 80.6f);
// 提交
editor.commit();
return true;
}
public static boolean read(Context context) {
SharedPreferences shared = context.getSharedPreferences(Constant.PATH,
Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE);
String name = shared.getString("pwd", null);
int age = shared.getInt("age", -1);
float weight = shared.getFloat("weight", 0.0f);
Log.d("FileIOUtilsShared", "name=" + name + " age=" + age + " weight="
+ weight);
return true;
}