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;
             }  
  • 相关阅读:
    Emacs教程
    华为上机测试 2015
    奇偶排序
    C语言中的EOF和回车不一样
    jquery 使用方法
    1116
    1115
    1109
    Oracle14~23
    get与post的区别
  • 原文地址:https://www.cnblogs.com/ShaoXin/p/7771911.html
Copyright © 2011-2022 走看看