BIBEKRBARAL
BIBEKRBARAL

Reputation: 4475

How to delete a file from an Android application

How can I delete a file from an Android application? Can I do it the same way I would for deleting a file in Java?

Upvotes: 3

Views: 11268

Answers (3)

Saeed-rz
Saeed-rz

Reputation: 1443

File file = new File(selectedFilePath);
boolean deleted = file.delete();

and set this permission
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
in AndroidManifest.xml file

Upvotes: 3

Zordid
Zordid

Reputation: 10469

The Android Developer Homepage has a really good Dev Guide section.

Answer to your question: Files can be deleted using: File.delete() method. (I found that by searching for "file delete" on the page above!)

But of course, there's much more to that: you need to understand how Android stores files and which files your application is allowed to modify! (basically only its own files, all the others are not accessible)

Upvotes: 2

SandroG
SandroG

Reputation: 136

    File file = new File(path);
    return file.delete();   

Upvotes: 1

Related Questions