byte[] buf = new byte[8192];
int len;
for (String filename :filenameToData.keySet()
) {
ZipEntry ze = new ZipEntry(filename + ".txt");
zos.putNextEntry(ze);
if(null != filenameToData.get(filename))
{
ByteArrayInputStream bis = new ByteArrayInputStream(modelDataMap.get(filename).getBytes());
while ( ( len = bis.read( buf ) ) > 0 ) {
zos.write( buf, 0, len );
}
}
zos.closeEntry();
}
response.setHeader("Content-Disposition","attachment; filename=\"" + zipname+".zip" + "\"");
response.setContentType("application/zip");
os.write(bos.toByteArray());
bos.close();
zos.close();
把字符串數據打包成壓縮包並返回瀏覽器提示下載
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.