Why is the file not deleted using file.delete ()?

I can not delete the file from sdcard.

File toDelete = new File(fname); boolean result=toDelete.delete(); 

The result is false. Reading and writing the same file works in one application. There are no open threads. There were no exceptions. I tried to make it writable just before deletion this way

 toDelete.setWritable(true); 

no effect. How is it possible that the system can write and read, but cannot delete the same file ???

+6
source share
2 answers

Use the code below that may help you.

  File fdelete = new File(file_dj_path); if (fdelete.exists()) { if (fdelete.delete()) { System.out.println("file Deleted :" + file_dj_path); } else { System.out.println("file not Deleted :" + file_dj_path); } } 

Refresh gallery after deleting image

 sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory()))); 

check this out: fooobar.com/questions/76442 / ...

+3
source

Try to do it

  File fileToDelete = new File(YourPath); boolean deleted = fileToDelete.delete(); 

Reinstall the card and check

  sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory()))); 
+1
source

All Articles