Search code examples
javaexceptionjarzip

What is the smallest, legal zip/jar file?


I hate generating an exception for things that I can simply test with an if statement. I know that a zero length zip/jar will trigger an exception if you try to access it using the java.util.zip/java.util.jar APIs. So, it seems like there should be a smallest file that these utility APIs are capable of working with.


Solution

  • According to ZIP file format specs a zip file should at least have the central directory structure that is 46 bytes long + 3 variable fields (check the spec by yourself).

    Maybe we should assume at least 1 entry that implies the file header for that entry.