Android-SD卡读写
adb shell
mksdkcard 50m d:\xxx\xxxx.img
挂载/卸载sd卡
<uses-permission
android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS">
<!---往SDCard写入数据->
<uses-permission
Android:name="android.permission.WRITE_EXTERNAL_STORAGE">
if(Environment.getExternalStorageState()
.equals(Environment.MEDIA_MOUNTED)) {
File sdCardDir = Environment.getExternalStorageDirectory();
File saveFile = new File(sdCardDir,"itcast.txt");
FileOutputStream fos = new FileOutputStream(saveFile);
}
Android共享首选项
轻量级的数据存储机制,适合存储软件配置参数,内部仍然是使用xml进行存储,位于
/data/data/<package name>./shared_prefs.
SharedPreferences sf = getSharedPreferences("itcast",Context.MODE_PRIVATE);
Editor editor = sharedPreferences.edit();//获取编辑器
editor.putString("name","传智播客");
editor.putInt("age".,4);
Editor.commit();//提交修改
注:文件名不需要加扩展名.自动加上
<map>
<string name="name">传智播客</string>
<int name="age" value="4"/>
</map>
//读取数据
String name = sharedPreferences.getString("name","");
Int age = sharedPreferences.getInt("age",1);
访问其他包中的共享首选项
Context otherAppsContext = createPackageContext("cn.itcast.action",Context.CONTEXT_IGNORE_SECURITY);
SharedPreferences sharesPreferences("itcast",Context.MODE_WORLD_READABLE);
或者 直接通过绝对路径
New File(/data/data/${otherpackagename}/shared_prefs/kk.xml);