gpt4 book ai didi

java - Android 无法删除文件

转载 作者:行者123 更新时间:2023-12-02 05:14:39 27 4
gpt4 key购买 nike

问题:

我想从 Android 设备的内部存储中删除视频文件。

Below code is in class that extends BaseAdapter and "file.delete()" method returns false

    File fdelete = new File(videolist.get(position).getVideopath());
Log.d(TAG,"Path to delete : "+videolist.get(position).getVideopath());
if (fdelete.exists()) {
Log.d(TAG,"DELETE EXIST");
if (fdelete.delete()) {
Log.d(TAG,"DELETED");
} else {
Log.d(TAG,"NOT DELETED");
}
}

" videolist.get(position).getVideopath() " returns this : "/storage/emulated/0/Download/jellyfish-3-mbps-hd-h264xgdhdudtudutdutdjtditditdtidjtditdjtdtkd.mkv"

最佳答案

试试这个

    private void deleteMedia(final String advName) {
File path = Environment.getExternalStorageDirectory();
File directory = new File(path.getAbsolutePath() + "/your directory name");

File[] files = directory.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return name.contains(advName);
}
});
if (files != null) {
for (int i = 0; i < files.length; i++) {
File file = files[i];
file.delete();
}
}
}

关于java - Android 无法删除文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56305270/

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