首页 | 源码下载 | 网站模板 | 网页特效 | 广告代码 | 网页素材 | 字体下载 | 书库 | 站长工具
会员投稿 投稿指南 RSS订阅
当前位置:主页>网络编程>jsp教程>资讯:Jsp页面实现文件上传下载

Jsp页面实现文件上传下载

www.jz123.cn  2008-09-02   来源:   中国建站    袁袁整理    我要投递新闻


        FileInputStream inStream = null;
        ZipOutputStream zos = null;
        InputStream is = null;
        String filepath = null;
        try{
         
            if ( fileType == 0 || fileType == 1){
                if ( fileType == 0 ){
                    filepath = downFileName;  
                }else{
                    filepath = zipFilePath + fileName;
                    String[] fileToZip = zipFileNames;
                                   
                    zos=new ZipOutputStream(new FileOutputStream(filepath));
                    ZipEntry ze=null;
                    byte[] buf=new byte[BUFSIZE];
                    int readLen=0;
                    for (int i= 0;i<fileToZip.length;i++){
                        File f= new File(fileToZip[i]);
       
                        ze=new ZipEntry(f.getName());
                        ze.setSize(f.length());
                        ze.setTime(f.lastModified());
       
                        zos.putNextEntry(ze);
                        is=new BufferedInputStream(new FileInputStream(f));
                        while ((readLen=is.read(buf, 0, BUFSIZE))!=-1) {
                            zos.write(buf, 0, readLen);
                        }
                        is.close();
                    }
                    zos.close();
                }
          
                inStream =new FileInputStream(filepath);  
  
                while((rtnPos=inStream.read(buffs)) >0)  
                    response.getOutputStream().write(buffs,0,rtnPos);  
                response.getOutputStream().close();  
                inStream.close();

上一篇:JSP网站开发环境的目录结构标准 下一篇:Jsp常用功能:CSV文件的生成与分析

评论总数:2 [ 查看全部 ] 网友评论


关于我们隐私版权广告服务友情链接联系我们网站地图