Paul Taylor Paul Taylor - 4 years ago 72
Java Question

Problem creating a multiple entry zip file with java

ANyone know whats wrong with this code for creating a zip file containing a number of entries

private File zipAttachments(List<File> licenses) throws IOException
byte[] buf = new byte[1024];
File licenseZip = new File("");
FileOutputStream fos = new FileOutputStream(licenseZip);
ZipOutputStream zip = new ZipOutputStream(fos);
for(File license:licenses)
ZipEntry zipEntry = new ZipEntry(license.getName());
FileInputStream in = new FileInputStream(license);
int len;
while ((len = > 0)
zip.write(buf, 0, len);

return licenseZip;

and the stack is ZIP file must have at least one entry

but im pretty sure that the licenses paramter is not an empty list so doesnt that mean I am creating zip entries ?

Answer Source

I think you're missing this as the first lines of your method:

if (licenses.isEmpty())
    throw new IllegalArgumentException("licenses is empty");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download