要求:
输入文件名,文件内容分别存储在手机内存和外存中,并且都可以读去取出来。
步骤:
1.创建一个名为CDsaveFile的Android项目
2.编写布局文件activity_main.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="hhh.exercise.cdsavefile.MainActivity" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/textView_inputFileName" android:textColor="#00ff00" android:textSize="26sp" /> <EditText android:id="@+id/editView_fileName" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:hint="@string/editView_fileName" android:maxLines="1" android:textColor="#ff0000" android:textSize="26sp" /> <requestFocus /> </LinearLayout> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/textView_inputFileContent" android:textColor="#00ff00" android:textSize="26sp" /> <EditText android:id="@+id/editView_fileContent" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:hint="@string/editView_fileContent" android:maxLines="2" android:minLines="2" android:textColor="#ff0000" android:textSize="26sp" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <Button android:id="@+id/button_saveToPhone" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="@string/button_saveToPhone" android:textColor="#ff00ff" android:textSize="24sp" /> <Button android:id="@+id/button_readFromPhone" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="@string/button_readFromPhone" android:textColor="#00ffff" android:textSize="24sp" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <Button android:id="@+id/button_saveToSD" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="@string/button_saveToSD" android:textColor="#ff00ff" android:textSize="24sp" /> <Button android:id="@+id/button_readFromSD" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="@string/button_readFromSD" android:textColor="#00ffff" android:textSize="24sp" /> </LinearLayout> <EditText android:id="@+id/editText_showResult" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:maxLines="3" android:minLines="3" android:hint="@string/editText_showResult" android:textColor="#cccc00" android:textSize="30sp" /> </LinearLayout>
网页题目:Android实现文件存储并读取的示例代码-创新互联
浏览地址:https://www.cdcxhl.com/article48/csighp.html
成都网站建设公司_创新互联,为您提供关键词优化、品牌网站建设、建站公司、外贸建站、ChatGPT、网站设计
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联