2
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();
}

I have create zip folder for multiple images in internal storage.Now i want to delete Zip files from the location and recreate same name zip folder in android.

Perform above code for delete zip folder but its not working
Please help me if anyone have solution
Thanks in advance..
Dragonthoughts
  • 2,180
  • 8
  • 25
  • 28
Krupali Shingala
  • 192
  • 2
  • 14

4 Answers4

0

after using delete() method in your File. filePath is a String containing the path to your zip file.

File file = new File(filePath);  

//must check if deleted is true. It is true if the file was successfully deleted

boolean deleted = file.delete();
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;
    }
Ranjan
  • 1,326
  • 18
  • 38
0

Give this a try!

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
      }
Tara
  • 692
  • 5
  • 23
0

File file = new File(deleteFilePath); boolean deleted = = file.deleted();

deleteFilePath is a String containing the path to your zip file.

if deleted is true. It is true if the file was successfully deleted.