• 通过输出流在前台显示zip包中的文件信息


    前台打印
           String previewXML = showZipFile(filePath); ServletOutputStream outputStream = response.getOutputStream(); response.reset();// 清空输出流 response.setHeader("Content-disposition", "attachment; filename=" + filePath.substring(filePath.lastIndexOf("\")+1));// 设定输出文件头 response.setContentType("application/xml");// 定义输出类型 outputStream.write(previewXML.getBytes()); outputStream.flush(); outputStream.close();

    拿到文件数据

    public  String showZipFile(String filePath)  {  
               ZipFile zf;
               StringBuffer sb = new StringBuffer();
               String substring = filePath.substring(filePath.lastIndexOf("\")+1);
               filePath = filePath.substring(0,filePath.lastIndexOf("\")+1);
                try {
                zf = new ZipFile(filePath);
                FileInputStream in = new FileInputStream(filePath);
                ZipInputStream zin = new ZipInputStream(in);  
                ZipEntry ze;
                 while ((ze = zin.getNextEntry()) != null) {  
                     if (ze.isDirectory()) {
                     } else {  
                        String name = ze.getName();
                        
                        if(name.equals(substring)) {
                         long size = ze.getSize();  
                         if (size > 0) {  
                             BufferedReader br = new BufferedReader(  
                                     new InputStreamReader(zf.getInputStream(ze)));  
                             String line;  
                             while ((line = br.readLine()) != null) {  
                                 sb.append(line);
                             }  
                             br.close();  
                         }  
                        }
                         continue;
                     }  
                 }  
                 zin.closeEntry();  
                 in.close();
                 zin.close();
                 return sb.toString();
                } catch (IOException e) {
                } 
                return null;
             }  
  • 相关阅读:
    007-搭建框架-开发AOP框架
    007-安装百度云,搜狗输入法,播放器
    006-重装yum
    005-快捷键,host,查看版本
    004-ibus输入法,快捷键,浏览器
    003-centos搭建idea开发java
    002-命令行模式安装图形界面
    006-网站统计中的数据收集原理及实现
    007-sql整体概述
    017-Hadoop Hive sql语法详解7-去重排序、数据倾斜
  • 原文地址:https://www.cnblogs.com/ShaoXin/p/7771911.html
Copyright © 2020-2023  润新知