public class ZipUtil
{
public static void createZipFile(String zipFileName, Collection fileNames) throws IOException
{
ZipOutputStream out = null;
FileInputStream in = null;
try
{
byte[] buf = new byte[1024];
out = new ZipOutputStream(new FileOutputStream(zipFileName));
for (Iterator iter2 = fileNames.iterator(); iter2.hasNext();)
{
String docImageName = (String)iter2.next();
in = new FileInputStream(docImageName);
String name = new File(docImageName).getName();
out.putNextEntry(new ZipEntry(name));
int len;
while ((len = in.read(buf)) > 0)
{
out.write(buf, 0, len);
}
out.closeEntry();
in.close();
}
out.close();
}
finally
{
if(in != null) in.close();
if(out != null) out.close();
}
}
}
java创建zip文件
最新推荐文章于 2024-06-25 14:15:43 发布