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

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -