从J2EE转向Android的第九天-----文件存储
16lz
2021-12-04
五一在家,学了SQLite和SharedPreferences,刚刚练了下Android的文件存储
读文件:
Context.openFileInput(String fileName)打开一个文件
FileInputStream is = this.openFileInput("test.txt");
is=this.getResources().openRawResource(R.raw.weakcover);
我遇到个问题就是我的文件放在raw文件夹下,但是当我向文件写数据的时候,数据时保存在模拟器中的data文件下的test.txt中,没有同步更新到raw下的文件中.
写文件:
Context.openFileOutput(String name,int mode) 当文件不存在时该文件将被创建
FileOutputStream out=this.openFileOutput("test.txt",MODE_APPEND);
读数据的时候跟java的一样,照搬,哈哈
is=this.getResources().openRawResource(R.raw.weakcover);
StringBuffer bfReadStr=new StringBuffer("");
byte[] buffer=new byte[1024];
int ch=0;
while((ch=is.read(buffer))!=-1){
bfReadStr.append(new String(buffer,"UTF-8"));
}
更多相关文章
- mybatisplus的坑 insert标签insert into select无参数问题的解决
- python起点网月票榜字体反爬案例
- NPM 和webpack 的基础使用
- 【阿里云镜像】使用阿里巴巴DNS镜像源——DNS配置教程
- android 读 txt
- Android编译系统(Android.mk文件详解-仅供参考)
- 如何在Activity调用surfaceView实现透明或半透明的效果
- Android(安卓)官方示例:android-architecture 学习笔记(二)之todo
- Android(安卓)Studio 应用目录结构说明