在Android中删除zip文件夹

时间:2018-08-07 12:40:26

标签: java android delete-file

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..

4 个答案:

答案 0 :(得分:0)

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

File file = new File(filePath);  

//必须检查删除是否为真。如果文件已成功删除,则为真

boolean deleted = file.delete();

答案 1 :(得分:0)

 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;
    }

答案 2 :(得分:0)

尝试一下!

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
      }

答案 3 :(得分:0)

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

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

如果删除为true。如果文件已成功删除,则为真。