【问题标题】:Delete zip folder in android在android中删除zip文件夹
【发布时间】:2018-08-07 12:40:26
【问题描述】:
Map<String, String> zip_properties = new HashMap<>();
zip_properties.put("create", "false");
URI zip_disk = URI.create(name);

/* Create ZIP file System */
try (FileSystem zipfs = FileSystems.newFileSystem(zip_disk, zip_properties)) 
{
   Path pathInZipfile = zipfs.getPath(name);
   // System.out.println("About to delete an entry from ZIP File" + 
     pathInZipfile.toUri() );
   Files.delete(pathInZipfile);
   //System.out.println("File successfully deleted");
} catch (IOException e) {
    e.printStackTrace();
}

我已经为内部存储中的多个图像创建了 zip 文件夹。现在我想从该位置删除 Zip 文件并在 android 中重新创建同名 zip 文件夹。

Perform above code for delete zip folder but its not working
Please help me if anyone have solution
Thanks in advance..

【问题讨论】:

  • @RanjanDas 我试试你的代码,但它只删除 zip 文件的内容,但不删除 zip 文件。
  • 给出 zip 文件的路径,而不是它的内容。
  • Zip_Folder_Path :: /storage/emulated/0/PhotoResizer/PhotoResizer_1533707372194.zip 我使用上述路径删除 zip 文件夹,但只删除 zip 文件夹的内容而不是 zip 文件。
  • 只做arraylist.clear();在我的情况下,重新创建 zipfile。它解决了我的问题。谢谢。

标签: java android delete-file


【解决方案1】:

在您的文件中使用 delete() 方法后。 filePath 是一个包含 zip 文件路径的字符串。

File file = new File(filePath);  

//必须检查deleted是否为真。文件删除成功则为真

boolean deleted = file.delete();

【讨论】:

    【解决方案2】:
     Use below method
    
         /**
         * Clear/Delete all the contents in file/Directory
         *
         * @param file file/folder
         * @return true on successfull deletion of all content
         * <b>Make sure file it is not null</b>
         */
        public boolean clearDirectory(@NonNull File file) {
            boolean success = false;
            if (file.isDirectory())
                for (File child : file.listFiles())
                    clearDirectory(child);
            success = file.delete();
            return success;
        }
    

    【讨论】:

      【解决方案3】:

      试试这个!

      public static final String ZIP_FILES_DIR = "Download/FolderNAME";    
      
      File directoryPath = new File(Environment.getExternalStorageDirectory()+ File.separator + ZIP_FILES_DIR);
          if (directoryPath.delete()) {
              //do whatever you want
            }
      

      【讨论】:

        【解决方案4】:

        文件 file = new File(deleteFilePath); 布尔删除 = = file.deleted();

        deleteFilePath 是一个包含 zip 文件路径的字符串。

        如果删除为真。如果文件被成功删除则为真。

        【讨论】:

          猜你喜欢
          • 2012-02-23
          • 1970-01-01
          • 2015-01-18
          • 2016-08-01
          • 2023-01-20
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多