Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Result of 'File.delete()' is ignored

I was trying to make a button which can delete a file (video file) which is downloaded by the app.

When I used File.delete() then the android studio says it will be ignored and by that I came to know that this is a problem with the Security stuff in android. And I would like to SURELY delete the file (in my case it is the video file downloaded by my app). Hope anyone help me out.

Here is the code I used:

path = "/some/folder/"
File file = new File(path);
file.delete();
like image 285
ЯVR Avatar asked Sep 19 '25 14:09

ЯVR


1 Answers

The warning that you are seeing is telling you that file.delete() returns a value, and that you are ignoring that returned value.

The issue is that you cannot know that the file was actually deleted unless you check that the call to file.delete() returns true.

So, to eliminate this warning, evaluate the return value, and appropriately handle the case where it is false.

like image 154
GreyBeardedGeek Avatar answered Sep 21 '25 07:09

GreyBeardedGeek