Android how to delete file in Internal Storage

Viewed 36

I got file image from Internal Storage. But when i want delete file image not working always return false My code:

var file=File("path_of_image")
        var check:Boolean=file.delete()
        if(check==true){
            
        }
        else{
            // always return false and can not delete file
        } ```
1 Answers

I think you are using the wrong path. Use context.getFilesDir for get your app internal files dir For example:

var file = File(context.getFilesDir().getPath() + File.separaror + "your_file_name")
Related