Android 内部存储文件读写权限
来源:互联网 发布:淘宝刷单好评 编辑:程序博客网 时间:2024/05/18 00:39
Android权限机制
* MODE_PRIVATE 私有文件
* MODE_WORLD_READABLE 全局可读文件
* MODE_WORLD_WRITEABLE 全局可写文件
* MODE_WORLD_READABLE + MODE_WORLD_WRITEABLE 全局可读可写
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" > <RadioGroup android:id="@+id/rg_mode" android:layout_width="wrap_content" android:layout_height="wrap_content"> <RadioButton android:id="@+id/rb_private" android:layout_width="wrap_content" android:layout_height="wrap_content" android:checked="true" android:text="私有文件" /> <RadioButton android:id="@+id/rb_readonly" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="全局可读文件" /> <RadioButton android:id="@+id/rb_writeonly" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="全局可写文件" /> <RadioButton android:id="@+id/rb_readwrite" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="全局可读可写文件" /> </RadioGroup> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:onClick="createFile" android:text="创建文件" /></LinearLayout>
public class MainActivity extends Activity { private RadioGroup rg_mode; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // 查找控件 rg_mode = (RadioGroup) findViewById(R.id.rg_mode); // 读取数据 FileInputStream fis; try { fis = new FileInputStream(new File("/data/data/com.cy.readwrite/files/private.txt")); BufferedReader br = new BufferedReader(new InputStreamReader(fis)); String line = br.readLine(); System.out.println("===================" + line); } catch (Exception e) { System.out.println("读取失败!"); e.printStackTrace(); } } public void createFile(View view){ // 点击事件 int id = rg_mode.getCheckedRadioButtonId(); try { FileOutputStream fos = null; switch (id) { case R.id.rb_private: System.out.println("创建私有文件"); fos = openFileOutput("private.txt", MODE_PRIVATE); fos.write("gagagagaga!!!!".getBytes()); break; case R.id.rb_readonly: System.out.println("创建全局可读文件"); fos = openFileOutput("readonly.txt", MODE_WORLD_READABLE); fos.write("gagagagaga!!!!".getBytes()); break; case R.id.rb_writeonly: System.out.println("创建全局可写文件"); fos = openFileOutput("writeonly.txt", MODE_WORLD_WRITEABLE); fos.write("gagagagaga!!!!".getBytes()); break; case R.id.rb_readwrite: System.out.println("创建全局可读可写文件");// /data/data fos = openFileOutput("readwrite.txt", MODE_WORLD_READABLE + MODE_WORLD_WRITEABLE); fos.write("gagagagaga!!!!".getBytes()); break; default: break; } if(fos != null){ // 关闭流 fos.close(); } } catch (Exception e) { e.printStackTrace(); Toast.makeText(this, "文件创建失败", 0).show(); } }}
参考:Android 存储
阅读全文
0 0
- Android 内部存储文件读写权限
- Android 内部存储中读写文件
- android内部存储读写文件详解
- 内部存储读写文件
- Android文件读写操作(assets 文件、 raw文件、内部存储文件、外部存储文件)
- Android -- 读写文件到内部ROM,SD卡,SharedPreferences,文件读写权限
- Android 内部文件存储
- android文件读写权限
- android读写文件权限
- android,内部存储,外部存储,权限理解
- 读写内部存储的文件数据
- 读写内部存储的文件数据
- 6.读写内部存储的文件
- Android内部存储改变读取权限
- android内部文件存储示例
- Android 访问内部存储文件
- Android的读写文件权限
- Android的读写文件权限
- https生成证书——keytool 用法总结
- UVA-514 Rails
- 浏览器连接不到网络
- 23种设计模式的通俗理解
- 【Angular】环境搭建
- Android 内部存储文件读写权限
- centos运行不了setup命令?怎么安装setup tools
- 大数据及人工智能基础知识复习系列1 二叉树及二叉搜索树
- 应该挖一口属于自己的井
- 数据结构——四
- mysql异常:You can't specify target table 'my' for update in FROM clause
- hexo的Next创建tags
- 2017百度之星资格赛 度度熊的午饭时光(dfs)
- TensorFlow基础知识5-会话(session)