Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete file from internal storage

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"); boolean deleted = file.delete(); 

And this is from another question, which was answered with:

File dir = getFilesDir(); File file = new File(dir, "my_filename"); boolean deleted = file.delete(); 

My example always returns false. I can see the file fx 2930.jpg in DDMS in eclipse.

like image 574
Crunch Avatar asked Mar 30 '11 12:03

Crunch


People also ask

How do I delete files from internal storage?

Choose a folder you wish to delete files from. Tap and hold each file you wish to delete, to put a check mark on it, then tap the More (three dots) icon in the top right corner. Select Delete from device from the drop-down menu. Then select Delete from device from the pop-up menu at the bottom.

How do I delete internal files on Android?

The most straightforward way to delete a file is to have the opened file reference call delete() on itself. myFile. delete() ; If the file is saved on internal storage, you can also ask the Context to locate and delete a file by calling deleteFile():

Can I delete everything in my internal storage?

Open up the Settings app. Tap on General Management and tap on Reset. Select the Factory data reset option. On the final screen, confirm by tapping Reset Device and Delete All.

What is internal storage?

Android Internal storage is the storage of the private data on the device memory. By default, saving and loading files to the internal storage are private to the application and other applications will not have access to these files.


1 Answers

The getFilesDir() somehow didn't work. Using a method, which returns the entire path and filename gave the desired result. Here is the code:

File file = new File(inputHandle.getImgPath(id)); boolean deleted = file.delete(); 
like image 124
Crunch Avatar answered Nov 15 '22 22:11

Crunch