Delete a folder on SD card

后端 未结 5 660
感动是毒
感动是毒 2020-11-29 04:24

I tried File.delete() but it doesn\'t work. How to delete a directory on SD card?

I\'m working on Android 2.1.

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-29 05:19

    You have to have all the directory empty before deleting the directory itself, see here

    In Android, you should have the proper permissions as well - WRITE_EXTERNAL_STORAGE in your manifest.

    EDIT: for convenience I copied the code here, but it is still from the link above

    public static boolean deleteDirectory(File path) {
        if( path.exists() ) {
          File[] files = path.listFiles();
          if (files == null) {
              return true;
          }
          for(int i=0; i

提交回复
热议问题