No one answered the original question Why? The answers just provide tips on how to do this.
So why?
Jar and zip files are compressed files that have a set of files or directives, commonly called records. The structure / format of jar / zip files is a sequential listing of entries (in addition to the header of the zip file format).
Each entry has a header that contains information about the entry, for example. its name, type, byte length (and others).
Now, using this sequential list of records, how would you remove a record from the middle of a file? This would leave a βholeβ in the middle of the file. The only way to delete a record (without re-creating the archive without deleting the record) will require copying the contents of the zip file, starting from the record to the beginning of the current (deleted) record, as well as cutting the length of the zip file along the length of the deleted record.
Imagine what this would mean if you have an archive with tens or hundreds of MB? If you delete the entry at the beginning, you will have to copy almost the entire contents of the file to several bytes (or kilobytes) so as not to leave a space in the file.
So why.
This structure makes it easy to add new entries, because they can be added to the end of the file easily, but (write) delete cannot be performed efficiently.
source share