user1066804
user1066804

Reputation: 55

I am trying to write a method to delete a file from the internal storage in Android device and

imagedirectory = new File(path);
imagepool = imagedirectory.listFiles();
Uri targetdelete = Uri.fromFile(imagepool[photoindex]); //photoindex is integer 1
File filetodelete = new File(targetdelete);
boolean deleted = filetodelete.delete();

I am receiving an error in this line

File filetodelete = new File(targetdelete);

it says targetdelete must be a string object.... I thought it was valid to put Uri object as the agrument when initializing a File object?

Thanks once again, wonderful experts on stack overflow!!

Upvotes: 0

Views: 58

Answers (1)

sgarman
sgarman

Reputation: 6182

Why not just do deleted = imagepool[photoindex].delete();

Upvotes: 1

Related Questions