使用java创建多条目zip文件时出现问题

使用java创建多条目zip文件时出现问题,java,zip,Java,Zip,有人知道创建包含多个条目的zip文件的代码有什么问题吗 private File zipAttachments(List<File> licenses) throws IOException { byte[] buf = new byte[1024]; File licenseZip = new File("license.zip"); FileOutputStream fos = new FileOutputStrea

有人知道创建包含多个条目的zip文件的代码有什么问题吗

    private File zipAttachments(List<File> licenses) throws IOException
    {
        byte[] buf = new byte[1024];
        File licenseZip = new File("license.zip");
        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);
            zip.putNextEntry(zipEntry);
            int len;
            while ((len = in.read(buf)) > 0)
            {
                zip.write(buf, 0, len);
            }
            zip.closeEntry();
            in.close();
        }
        zip.close();

        return licenseZip;
    }

但是我很确定licenses参数不是一个空列表,所以这不意味着我正在创建zip条目吗?

我认为您缺少这个作为方法的第一行:

if (licenses.isEmpty())
    throw new IllegalArgumentException("licenses is empty");

很确定?你为什么不直接输出列表的大小或者什么来检查是否确定呢?是的,你是对的,不幸的是,我昨天不能轻易地测试这个,但是现在已经测试了,所以问题必须进一步解决。
if (licenses.isEmpty())
    throw new IllegalArgumentException("licenses is empty");