Android课堂笔记4——文件读写
来源:互联网 发布:周末网络理财平台 编辑:程序博客网 时间:2024/06/10 16:57
文件读写
1.读取内部和外部储存
File类:表示文件或文件夹的路径
在/data/data/‘应用包名’/files目录下新建文件
File file=new File(getFilesDir(),"testFile");
FileOutputStream:在文件中写入信息
String s="写入字符";try { FileOutputStream out=openFileOutput("testFile", Context.MODE_PRIVATE); out.write(s.getBytes()); out.close();} catch (Exception e) { e.printStackTrace();}
得到外部储存路径
File exFile=Environment.getExternalStorageDirectory();exFile=new File(exFile,"testFile2");Log.d("MainActivity",exFile.getAbsolutePath());Log:MainActivity: /storage/sdcard0/testFile2
2.读取assets文件
try { InputStream inputStream=getResources().getAssets().open("testFile");} catch (IOException e) { e.printStackTrace();}
3.读取raw文件
InputStream inputStream=getResources().openRawResource(R.raw.test);
4.SharedPrefrences
SharedPrefrences是一个轻量级的储存类型,数据储存在xml文件中
SharedPreferences sharedPreferences=getSharedPreferences("test",MODE_PRIVATE);SharedPreferences.Editor editor=sharedPreferences.edit();editor.putString("testKey","testValue");editor.commit();
0 0
- Android课堂笔记4——文件读写
- Android 课堂笔记——shape
- Android课堂笔记——selector
- Android课堂笔记——dialog对话框
- Android课堂笔记——ViewPager
- Android课堂笔记——Menu
- Android课堂笔记—SQLite3和ContentProvider
- linux常用文件处理命令——课堂笔记
- 课堂笔记--文件操作
- Android课堂笔记——ToggleButton和Switch
- Android课堂笔记——BaseAdapter及其优化
- Android课堂笔记——Notification通知栏
- day01:Android课堂笔记
- Android学习笔记(4)————Android的私人文件夹的文件读写操作
- PHP学习笔记——文件读写
- Python学习笔记——文件读写
- python 笔记 读写文件——12.26
- Android学习笔记(11)————Android的私人文件夹的文件读写操作
- jdk-动态代理
- SpringMVC中使用Interceptor拦截器
- 在Windows下搭建React Native Android开发环境
- UITableView的编辑模式
- 正则表达式基本语法
- Android课堂笔记4——文件读写
- 大数据时代单表数据同步之SPARK实现(一)
- printf相关
- IOS打包发布APP的所有详细流程
- centOS7初体验
- hibernate4 could not initialize proxy - no Session
- 预处理找到前N个质数
- php单元测试的优缺点
- Linux 进程学习(四)------ sigaction 函数