我使用了
File f=new File(MyPath);
f.delete();
我使用了权限WRITE_EXTERNAL_STORAGE
和READ_EXTERNAL_STORAGE
,但在Android 5上无法正常工作。
Logcat消息:
java.io.FileNotFoundException: storage/external_SD/mm.txt: open failed: EACCES (Permission denied)
清单文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mahestan_programming.myapplication">
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
自Android 4.4版本以后,我们无法在Micro SD卡中删除和写入文件,因为它现在是只读的。