gpt4 book ai didi

android - 如何从Android 5中的外部存储中删除文件

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:20:37 27 4
gpt4 key购买 nike

我用过

File f=new File(MyPath);
f.delete();

并且我使用了权限 WRITE_EXTERNAL_STORAGEREAD_EXTERNAL_STORAGE,但它在 Android 5 中不起作用。

Logcat 消息:

java.io.FileNotFoundException: storage/external_SD/mm.txt: open failed: EACCES (Permission denied)  

list 文件:

<?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>

WE CANNOT DELETE AND WRITE FILES FROM MICRO SD-CARD SINCE VERSION 4.4. It is read only now.

最佳答案

请仔细检查您的文件路径,路径如下所示:

String filePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Audio/audio_20160622_081844.3gp";
File file = new File(filePath);
if (file.exists()) {
file.delete();
}

关于android - 如何从Android 5中的外部存储中删除文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38430010/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com