Re: ZipOutputStream
problem solved. This is how it must be done:
public void create(ArrayList<FileItem> list,String path, String
fileName) {
// Create a buffer for reading the files
byte[] buf = new byte[1024];
System.out.print("Create " + fileName + ": ");
try {
ZipOutputStream out = new ZipOutputStream(new
FileOutputStream(path + fileName));
out.setMethod(ZipOutputStream.DEFLATED); // file mimetype
must be uncompressed
out.setLevel(Deflater.DEFAULT_COMPRESSION);
// Compress the files
for (FileItem fi : list) {
String fn = fi.dir + fi.fileName;
FileInputStream in = new
FileInputStream(root.getPath() + "\\" + fn);
// Add ZIP entry to output stream.
ZipEntry z = new ZipEntry(fn);
if (fn.equals("mimetype")) {
z.setMethod(ZipOutputStream.STORED); // file
mimetype must be uncompressed
// These three MUST be set. However, I think they may be set to
anything...
z.setSize(20); // length of data
z.setCompressedSize(20);
z.setCrc(0x2cab616f);
}
else {
z.setMethod(ZipOutputStream.DEFLATED);
}
out.putNextEntry(z);
// Transfer bytes from the file to the ZIP file
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
// Complete the entry
out.closeEntry();
in.close();
}
// Complete the ZIP file
out.close();
System.out.println("OK.");
}
catch (IOException e) {
System.out.println(e.getMessage());
}
}