Java android delete File -
i want delete file (pdf file) did :
boolean deleted = fileslist.get(pos).delete();
but when in phone see file , application doesn't see file
to delete file directory, can use method:
public static void deletefile(file directory, string filename) { if (directory.isdirectory()) { for(file file : directory.listfiles()) { if (file.getname().contains(filename)) { if (file.isfile()) { if (file.exists()) { file.delete(); } } } } } }
and if want delete entire directory:
public static void deletedirectory(file directory) { if (directory.isdirectory()) (file child : directory.listfiles()) deletedirectory(child); directory.delete(); }
as mentioned ylmzekrm1223
, should provide permissions read , write storage in androidmanifest.xml, before attempting delete file or directory.
Comments
Post a Comment