1

For .zip file we have, in Java, ZipInputStream and ZipOutputStream for reading from and writing to zip file.

    zin = new ZipInputStream(new FileInputStream("xx.zip"));
    ZipEntry entry =  zin.getNextEntry();
    while (entry != null) {
        String name = entry.getName();
        File file = new File(name);
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file));
        byte[] bytesIn = new byte[1024];
        while ((int read = zipIn.read(bytesIn)) != -1) {
            bos.write(bytesIn, 0, read);
        }
        bos.close();
        // code for renaming file ... here ...
        // . . . 
        entry = zin.getNextEntry();
    }
    zin.close();

And, similarly for inflating .gz using GZIPInputStream. Since, .gz files have only one content, the zipentry is not required. We may directly inflate it using name as .gz file (without the suffix). My question is:

Can I rename the content of .zip (andd .gz also) without inflating the content(s)? In .gz file, since we have same name of .gz file and the content, if we rename the .gz file, that would rename its content too.

For .zip file, can I simply rename ZipEntry without completely inflating?

Please suggest.

Dr. Debasish Jana
  • 6,980
  • 4
  • 30
  • 69

1 Answers1

1

Zip4j has a feature to rename files in the zip. It supports only zip files though, and not gzip.