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 ?
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".
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.