1
任何人都知道什麼是錯,此代碼用於創建包含多個項目問題創造了Java多次入境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;
}
和堆棧中的zip文件是
java.util.zip.ZipException: ZIP file must have at least one entry
at java.util.zip.ZipOutputStream.finish(ZipOutputStream.java:304)
at java.util.zip.DeflaterOutputStream.close(DeflaterOutputStream.java:146)
at java.util.zip.ZipOutputStream.close(ZipOutputStream.java:321)
但即時通訊相當確定許可證參數不是一個空列表,所以這不意味着我正在創建zip條目?
很肯定?你爲什麼不輸出列表的大小或者什麼來檢查確定的? – berry120