安卓中创建别的应用程序可以读写的文件
2016-07-04 22:07
295 查看
public class MainActivity
extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
/*得到一个文件的输出流,文件的位置/data/data/包名/files/haha.txt
* File file = new File(getFilesDir(),"haha.txt");
FileOutputStream fos = new FileOutputStream(file);*/
FileOutputStream fos = openFileOutput("readable.txt",
MODE_WORLD_READABLE);
fos.write("dafa".getBytes());
fos.close();
fos = openFileOutput("writeable.txt",
MODE_WORLD_WRITEABLE);
fos.write("dafa".getBytes());
fos.close();
fos = openFileOutput("public.txt",
MODE_WORLD_WRITEABLE+MODE_WORLD_READABLE);
fos.write("dafa".getBytes());
fos.close();
fos = openFileOutput("private.txt",
MODE_PRIVATE);
fos.write("dafa".getBytes());
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
/*得到一个文件的输出流,文件的位置/data/data/包名/files/haha.txt
* File file = new File(getFilesDir(),"haha.txt");
FileOutputStream fos = new FileOutputStream(file);*/
FileOutputStream fos = openFileOutput("readable.txt",
MODE_WORLD_READABLE);
fos.write("dafa".getBytes());
fos.close();
fos = openFileOutput("writeable.txt",
MODE_WORLD_WRITEABLE);
fos.write("dafa".getBytes());
fos.close();
fos = openFileOutput("public.txt",
MODE_WORLD_WRITEABLE+MODE_WORLD_READABLE);
fos.write("dafa".getBytes());
fos.close();
fos = openFileOutput("private.txt",
MODE_PRIVATE);
fos.write("dafa".getBytes());
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
相关文章推荐
- jdk-logging、log4j、logback日志介绍及原理一
- Android Canvas drawArc方法介绍
- 匹配电话号码是不是有效
- call,apply简单的模拟和实现
- cookie,localStorage,sessionStorage三者的联系
- QTextEdit中选中文本修改字体与颜色,全部文本修改字体与颜色(设置调色板的前景色、背景色、文字颜色以及基色)
- 静态变量(atuomatic) 动态变量 (static) 常量 const
- 安卓中向sd卡写文件
- 补充第二问
- 如何去除ci框架中显示的index.php
- ES6新特性中的Module
- LeetCode(四)——Intersection of Two ArraysII
- poj 2152 Fire 树形DP
- UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-13: ordinal not i│ n range(128)
- 我对MVC和MVP的一些理解
- C语言练习题每练 5 对于一个字符串,找到第一次重复出现的字符。
- ORA-01109 错误
- 习题8-11 UVA - 1615 Highway 高速公路 (区间枚举)
- sql case when
- java实现栈