try {
OutputStream os = res.getOutputStream();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ZipOutputStream zipOut = new ZipOutputStream(baos);
ZipEntry entry = new ZipEntry("goods.txt");
zipOut.putNextEntry(entry);
zipOut.write(bytes, 0, bytes.length);
res.reset();
res.setContentType("application/OCTET-STREAM;charset=GBK");
res.setHeader("pragma", "no-cache");
res.addHeader("Content-Disposition", "attachment;filename=goods.zip");
os.write(baos.toByteArray(), 0, baos.toByteArray().length);
zipOut.flush();
zipOut.closeEntry();
baos.close();
zipOut.close();
os.close();
} catch (Exception e) {
logger.error(e,e);
}
請參看,希望對你有用
http://snowolf.iteye.com/blog/644591