java压缩多个文件并且返回流示例
这个类可以压缩多个文件并且返回流,在程序中可以再操作返回的流做其它功能,比如验证MD5,下面看代码吧 复制代码 代码如下: /** * 方法描述:<b>测试类</b></br> */ public class TestFileStream{ //文件和压缩包存储的位置 StringtempFilePath="C:/temp/" List<String>fileList=newArrayList<String>(); fileList.add(tempFilePath+"file1.txt"); fileList.add(tempFilePath+"file2.png"); fileList.add(tempFilePath+"file3.xls"); //生成的压缩包名称 StringzipName="fileData"; //返回流 ByteArrayOutputStreamoutputStream=fileToZip(fileList,fileData,tempFilePath); //页面输入压缩包流 byte[]buffer=outputStream.toByteArray(); //清空response response.reset(); //设置response的Header response.addHeader("Content-Disposition", "attachment;filename="+ newString(("dataFile.zip").getBytes("gb2312"),"ISO8859-1")); response.addHeader("Content-Length",""+outputStream.size()); toClient=newBufferedOutputStream(response.getOutputStream()); response.setContentType("application/octet-stream"); toClient.write(buffer); toClient.flush(); } /** for(intj=0,len=filedata.size();j<len;j++) } } ByteArrayOutputStreambaos=null; 您可能感兴趣的文章:
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |