下一篇:Android数据存储————文件存储(外部存储)https://blog.csdn.net/sinat_29675423/article/details/85705545
存储特点
将数据存储在app的目录下,内部存储的数据只能被自己的应用程序访问到,存储空间有限。
存储位置
/data/data/<package_name>/files
存储模式
MODE_PRIVATE : 覆盖
MODE_APPEND: 追加
方法
保存:openFileInput(filename, mode)
读取:openFileOutput(filename)
例子:存储、读取字符串
将输入框中的字符串保存到内部存储路径中,并且读取存储的字符串到文本框中显示。
布局文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<EditText
android:id="@+id/etNote"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"/>
<Button
android:id="@+id/btnSave"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="保存"
android:onClick="onClick"/>
<Button
android:id="@+id/btnGet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:<