ЯVR
ЯVR

Reputation: 89

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();

Upvotes: 4

Views: 8338

Answers (2)

ЯVR
ЯVR

Reputation: 89

I have fixed the issue.

The issue is THE FILE I AM TRYING TO DELETE DOES NOT EXIST. I HAVE NOT MENTIONED THE CORRECT DIRECTORY (whereas I need to mention another folder in which my files exist)

Thanks GreyBeardedGeek for saying me to know if the file.delete() returns true or false so that I can handle it if it returns false.

#FirstStackOverflowQuestionResolved :-)

Upvotes: 1

GreyBeardedGeek
GreyBeardedGeek

Reputation: 30088

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.

Upvotes: 7

Related Questions