zoukankan      html  css  js  c++  java
  • 通过输出流在前台显示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;
             }  
  • 相关阅读:
    css之页面顶部阴影
    css之使用 :not() 在菜单上应用/取消应用边框
    CSS之黑白图像
    AMD/CMD规范
    HTTP学习笔记
    MUI之ajax获取后台接口数据
    Git提交代码规范
    Unicode与UTF-8/UTF-16/UTF-32的区别
    系统编程书籍推荐
    单口双线PC连接转换器 手机电脑耳机转接线
  • 原文地址:https://www.cnblogs.com/ShaoXin/p/7771911.html
Copyright © 2011-2022 走看看