How to erase files from your SD card on Android

Asked 2 years ago, Updated 2 years ago, 20 views

I created a program that sends files by email. I want to erase the image file after sending the email. Is there a way to erase the file?

myFile.delete(); I tried it like this, but the file doesn't erase. For your information, I also allowed access to the SD card.

android

2022-09-22 15:51

1 Answers

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

You have to do it like this. And the path to the file you want to erase must be the absolute path, as shown in the example below. /sdcard/YourCustomDirectory/ExampleFile.mp3


2022-09-22 15:51

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.