java io_error ai_generated true

java.util.zip.ZipException: ZIP 文件必须至少包含一个条目

java.util.zip.ZipException: ZIP file must have at least one entry

ID: java/zip-exception-unsupported-feature

其他格式: JSON · Markdown 中文 · English
92%修复率
86%置信度
1证据数
2023-08-01首次发现

版本兼容性

版本状态引入弃用备注
Java 8 active
Java 11 active
Java 17 active
Java 21 active

根因分析

ZipException 在尝试读取或处理空的 ZIP 文件(不包含任何条目)时抛出,通常是由于下载失败或归档创建损坏。

English

ZipException is thrown when attempting to read or process a ZIP file that is empty (contains no entries), often due to a failed download or corrupted archive creation.

generic

官方文档

https://docs.oracle.com/javase/8/docs/api/java/util/zip/ZipException.html

解决方案

  1. Verify the ZIP file integrity by checking its size and content before processing: if (zipFile.size() == 0) { throw new IOException("Empty ZIP file"); } else { try (ZipInputStream zis = new ZipInputStream(new FileInputStream(zipFile))) { ZipEntry entry = zis.getNextEntry(); if (entry == null) { throw new IOException("ZIP file has no entries"); } } }
  2. Re-download or regenerate the ZIP file from the source, ensuring the transfer is complete and the file is not truncated. Use checksums (e.g., MD5) to verify integrity.

无效尝试

常见但无效的做法:

  1. 80% 失败

    ZIP files have a specific structure; manual edits without understanding the format usually result in an invalid archive.

  2. 90% 失败

    The underlying issue (failed download or generation) remains unsolved; the new file may also be empty.