Delete file from internal storage

前端 未结 8 1645
借酒劲吻你
借酒劲吻你 2020-11-30 00:28

I\'m trying to delete images stored in internal storage. I\'ve come up with this so far:

File dir = getFilesDir();
File file = new File(dir, id+\".jpg\");
bo         


        
8条回答
  •  [愿得一人]
    2020-11-30 01:02

    File file = new File(getFilePath(imageUri.getValue())); 
    boolean b = file.delete();
    

    is not working in my case.

    boolean b = file.delete();                 // returns false
    boolean b = file.getAbsolutePath.delete(); // returns false 
    

    always returns false.

    The issue has been resolved by using the code below:

    ContentResolver contentResolver = getContentResolver();
    contentResolver.delete(uriDelete, null, null);
    

提交回复
热议问题