0

I have a ZIP file (actually EPUB ebook, which is the same as ZIP), and when I try to open it with a line like:

ZipFile zf = new ZipFile("/path/filename.epub");

I get "java.util.zip.ZipException: invalid CEN header (duplicate entry)" in java.util.zip.ZipFile.open(Native Method), and cannot read this file. Other ZIP utilities, e.g. command line unzip, WinRar, other ebook readers - read this file fine. Is there anyway to ignore this exception and still open a valid ZipFile?

Note: try/catch is not helpful here, as it does not allow me to read this file. The only possibility I see is to open this file with my own native code, re-compress it avoiding the (benign, not fatal) duplicate entry in the header, save as a temp file and return to Java to read this temp file instead. I hope for a better solution...

Patrick
  • 3,578
  • 5
  • 31
  • 53
gregko
  • 5,642
  • 9
  • 49
  • 76
  • What is your Java version? – Patrick Jun 12 '20 at 13:23
  • This is on Android, I compile with Java 8 compatibility. I examined this file more closely, it has double entries with the same internal file names, so when some utility extracts it, it needs to know which file to keep or overwrite. I guess there is no way to avoid Java exception in this case, but deal with the problem manually... – gregko Jun 12 '20 at 17:37

0 Answers0