2

I'm working on Minecraft Mod Installer and thinking about moving the engine from C# to Java would like to now if it is possible to copy some files from one zip to another without extracting them to a temporary folder and if this possible how would I go about this?

In the old engine it decompressed the files to a temp folder then added them to the Minecraft.jar

Ryan Leach
  • 4,262
  • 5
  • 34
  • 71
Liam Haworth
  • 848
  • 1
  • 9
  • 27

1 Answers1

3

The native zip support in jre can do it. Try this:

void substitute(ZipInputStream zis, ZipOutputStream zos) {
  for (ZipEntry ze = zis.getNextEntry(); ze != null; ze = zis.getNextEntry()) {
    if (ze.getName() is what you want to copy) {
      zos.putNextEntry(ze)
      Array[Byte] buffer = new Array[Byte](1024)
      for (int read = zis.read(buffer); read != -1; read = zis.read(buffer)) {
        zos.write(buffer, 0, read)
      }
      zos.closeEntry
    }
  }
  zos.close()
  zis.close()
}

Note: the data inside zip file is decompressed and compressed again.

Zang MingJie
  • 5,164
  • 1
  • 14
  • 27