Delete file from internal storage

前端 未结 8 1619
借酒劲吻你
借酒劲吻你 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 00:56
    String dir = getFilesDir().getAbsolutePath();
    File f0 = new File(dir, "myFile");
    boolean d0 = f0.delete(); 
    Log.w("Delete Check", "File deleted: " + dir + "/myFile " + d0);
    

    The code File dir = getFilesDir(); doesn't work because this is a request for a File object. You're trying to retrieve the String that declares the path to your directory, so you need to declare 'dir' as a String, and then request that the directory's absolute path in String form be returned by the constructor that has access to that information.

    0 讨论(0)
  • 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);
    
    0 讨论(0)
提交回复
热议问题