1

My Zip File structure is something like this:

t1.zip --> t2.zip --> sample.txt

I want to replace sample.txt. If it's one level, I was able to do it. Please help me with multi level nested zip files.

My Sample Code

ZipFile zipFile = new ZipFile(new File("t1.zip");
ZipArchiveEntry ze = zipFile.getEntry("t2.zip"); // So It works fine

I tried

ZipArchiveEntry ze = zipFile.getEntry("t2.zip/sample.txt"); // returns null

My intention was to follow Example from the apache's documentation page as this

ZipArchiveEntry entry = new ZipArchiveEntry(new File("sample.txt")); // Should I t2.zip/sample.txt ?
entry.setSize(size);
zipOutput.putArchiveEntry(entry);
zipOutput.write(contentOfEntry);
zipOutput.closeArchiveEntry();

But I am not clear, how to put the archive entry 2 level inside ?

Vinod Jayachandran
  • 3,726
  • 8
  • 51
  • 88

1 Answers1

-1

You have to use

new ZipArchiveEntry(new File("sample.txt"), "sample.txt");

to set the file into the root folder and

new ZipArchiveEntry(new File("sample.txt"), "new folder/sample.txt");

to set into a new folder called "new folder".

Chexpir
  • 1,876
  • 18
  • 33