我想从android设备的内部存储中删除视频文件。
下面的代码在扩展BaseAdapter的类中,并且“ file.delete()”方法返回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()”返回以下内容:“ /storage/emulated/0/Download/jellyfish-3-mbps-hd-h264xgdhdudtudutdutdjtditditdtidjtditdjtdtkd.mkv”
答案 0 :(得分:0)
尝试一下
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();
}
}
}