FileOutputStream和FileinputStream的使用
android 6.0以上的版本需要手动的写权限
这里实验的使用的是android4.4版本
第一步:编写布局文件
<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=".MainActivity" >
<EditText
android:id="@+id/edit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="写入数据"/>
<Button
android:id="@+id/btn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="读取数据"/>
</LinearLayout>
第二步: 给应用权限
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
第三步:写Mianactivity.java
3.1 定义对象
private EditText edit;
private Button btn1;
private Button btn2;
private boolean temp=false;
private String text;
private String FILENAME="/abcd.txt";
3.2 思路要清晰,先写出 读写功能代码
按钮 btn1 设置监听
btn1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
temp=write(edit.getText().to