I use this code:
String path = "mnt/sdcard/ten-file.mp3";
File file = new File(path);
boolean result = file.delete();
But it doesn't delete the file. Any advice?
I use this code:
String path = "mnt/sdcard/ten-file.mp3";
File file = new File(path);
boolean result = file.delete();
But it doesn't delete the file. Any advice?
String fileName = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "ten-file.mp3";
File soundFile = new File(fileName);
if (soundFile.exists())
{
boolean result = file.delete();
}
Manifest permission
uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
You want to make sure that the file exists prior to actually deleting the file:
File file = getBaseContext().getFileStreamPath("/sdcard/appname/data.xml");
if(file.exists()) {
boolean result = file.delete()
}
The issue I think with your original code is that you didn't actually test to make sure the file existed. You just created a file variable then told it delete it. I referred to the following question from an individual who had a similar problem to you: