我想从外部存储中删除文件,例如使用路径:
String path = "/whatsapp/images/myfile.jpg"
我使用下面的代码删除此文件,但无效:
File file = new File(Environment.getExternalStorageDirectory()+path);
public void delete(File file,Context context){
if(file.exists()){
boolean deleted = file.delete();
Toast.makeText(context,"File Successfully removed",Toast.LENGTH_SHORT).show();
}
else{
Toast.makeText(context,"File is not here!",Toast.LENGTH_SHORT).show();
}
}
我也在清单文件中写了必要的权限。