R
Roedy Green
I can create zip files that Winzip says are valid.
All the lengths are there. They pass the test.
I can read zip files that Winzip creates.
However, I can't read zip files that I create in Java with
ZipOutputSTream. It claims the lengths of each entry are 0.
Is there some trick to making this work?
Here is a slightly simplified version of what I am doing to create the
zip:
String elementName = "adir/afile.txt";
ZipEntry entry = new ZipEntry( elementName );
File elementFile = new File ( "adir/afile.txt" );
entry.setTime( elementFile.getLastModified() );
int fileLength = (int) elementFile.length();
entry.setSize( fileLength );
FileInputStream fis = new FileInputStream ( elementFile );
byte[] wholeFile = new byte [ fileLength ];
int bytesRead = fis.read( wholeFile, 0 /* offset */, fileLength
);
fis.close();
// no need to setCRC, computed automatically.
zip.putNextEntry( entry );
zip.write( wholeFile, 0, fileLength );
zip.closeEntry();
I am getting the horrible feeling that ZipOutputstream is stupidly
designed so that it is up to you to fill in fields like size, CRC,
compressed size by ESP, otherwise only the summary at the end of the
file is accurate.
All the lengths are there. They pass the test.
I can read zip files that Winzip creates.
However, I can't read zip files that I create in Java with
ZipOutputSTream. It claims the lengths of each entry are 0.
Is there some trick to making this work?
Here is a slightly simplified version of what I am doing to create the
zip:
String elementName = "adir/afile.txt";
ZipEntry entry = new ZipEntry( elementName );
File elementFile = new File ( "adir/afile.txt" );
entry.setTime( elementFile.getLastModified() );
int fileLength = (int) elementFile.length();
entry.setSize( fileLength );
FileInputStream fis = new FileInputStream ( elementFile );
byte[] wholeFile = new byte [ fileLength ];
int bytesRead = fis.read( wholeFile, 0 /* offset */, fileLength
);
fis.close();
// no need to setCRC, computed automatically.
zip.putNextEntry( entry );
zip.write( wholeFile, 0, fileLength );
zip.closeEntry();
I am getting the horrible feeling that ZipOutputstream is stupidly
designed so that it is up to you to fill in fields like size, CRC,
compressed size by ESP, otherwise only the summary at the end of the
file is accurate.