最终效果图,点击save会保存到文件中,点击show会从文件中读取出内容并显示。
main.xml
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- >
- <TextView
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="请您输入要保存的内容:"
- />
- <EditText
- android:id="@+id/addText"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:hint="请您在此处输入文件内容!"
- />
- <Button
- android:id="@+id/addButton"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="save"
- />
- <Button
- android:id="@+id/showButton"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="show"
- />
- <TextView
- android:id="@+id/showText"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- />
-
- </LinearLayout>
activity代码
其他的都为默认。
关于文件保存的路径可以通过ADT携带的File Explorer工具进行查看。如何调出File Explorer工具呢;我们可以通过Windows--showView--others-android下面看到File Explorer。这里是我的一个截图。
对于这个程序,基本上没什么难点,就是纯粹的java流知识。唯一不同的就是context为我们提供了两个方法来获取输入输出流。简单、方便、快捷啊。
http://blog.csdn.net/chenzheng_java/article/details/6214261
android文件的写入与读取---简单的文本读写context.openFileInput() context.openFileOutput(),布布扣,bubuko.com
android文件的写入与读取---简单的文本读写context.openFileInput() context.openFileOutput()
原文:http://www.cnblogs.com/daishuguang/p/3868601.html