简介
为了这个系列,我的代码已经准备到了第150天了。接下来的内容会越来越精彩,我们也越来越开始进入Android的一些高级功能上的编程了。今天我们就要讲Android中对本地文件进行读写的全过程。
课程目标
- 输入文件名、输入文件内容后按【保存到SD卡】,可以把文件保存到SD卡根目录;
- 输入文件名,按【读取SD卡中的文件】,可以根据输入的文件名把文件内容显示成Toast;
- 搞清Android中对于SD卡读写时所需要的静态权限申请、动态权限申请;
以上一共我们有3个目标,根据目标下面开始教程。
UI端
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"