I am implementing an application which generates and create files in External storage. How can I remove that?
I added following code and still I am getting the same problem. See my code below:
String fullPath = "/mnt/sdcard/";
System.out.println(fullPath);
try{
File file = new File(fullPath, "audio.mp3");
if(file.exists()){
boolean result = file.delete();
System.out.println("Application able to delete the file and result is: " + result);
// file.delete();
}else{
System.out.println("Application doesn't able to delete the file");
}
}catch (Exception e){
Log.e("App", "Exception while deleting file " + e.getMessage());
}
In the LogCat I am getting Application able to delete the file and result is:false. I attached my screen shot after executing this.
File file = new File(selectedFilePath);
boolean deleted = file.delete();
where selectedFilePath is the path of the file you want to delete - for example:
/sdcard/YourCustomDirectory/ExampleFile.mp3
I think you forgot to put the write permission in your AndroidManifest.xml file, that's why delete() always return false.
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With