Frage

How could you delete a directory containing files on android assets directory.

I tried doing this but does not work.

try {
         listaAssets = getAssets().list("");
    } catch (IOException e) {
         e.printStackTrace();
    }

for(String s : listaAssets){
     deleteFolder(s)
}

public void deleteFolder(String path){
    File folder = new File(path);
    File [] list;
    int num =0;
    boolean del = false;
    try{
        list = folder.listFiles();
        num = list.length;
        for (int i = 0; i<num; i++){
            list[i].delete();
        }
        if(folder.delete()){
            del = true;
        }else{
            del = false;
        }
    }catch(Exception e){
        Log.e("ERROR","Error: "+e.getMessage());
    }
}

Error: null

War es hilfreich?

Lösung

How could you delete a directory containing files on android assets directory.

You cannot delete (or modify) assets at runtime. They are read-only.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top