zoukankan      html  css  js  c++  java
  • 读取压缩文件下多级目录的文件(按行读取)

    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.util.ArrayList;
    import java.util.Enumeration;
    import java.util.List;
    
    import org.apache.tools.zip.ZipEntry;
    import org.apache.tools.zip.ZipFile;
    
    public class ZipUtil {
    
    	/**
    	 * 读取压缩文件下多级目录的文件(按行读取)
    	 * @author  zhengqiang
    	 */
    	public List<String> printZipTxt(String zipPath) throws IOException{
    		List<String> list = new ArrayList<String>();
    		
    		ZipFile zipFile=new ZipFile(zipPath); 
    		for (Enumeration<? extends ZipEntry> e = zipFile.getEntries(); e.hasMoreElements();){
    			ZipEntry entry=e.nextElement();
    			if(!entry.isDirectory()){
    				
    				BufferedReader br=new BufferedReader(new InputStreamReader(zipFile.getInputStream(entry)));
    				String line = "";
    				while((line = br.readLine()) != null){
    					if(line.length() > 0){
    						list.add(line);
    					}
    				}
    				br.close();
    			}
    		}
    		return list;
    	}
    }
    

      

  • 相关阅读:
    JSP的作用域与COOKIE
    jsp数据交互
    JSP基本使用方式
    分层架构的初步理解
    JDBC的基本应用
    HTML5新标签
    弹性布局
    解决js获取兄弟节点的兼容问题
    js去重函数(封装函数)
    封装日期函数
  • 原文地址:https://www.cnblogs.com/zqzdong/p/6438925.html
Copyright © 2011-2022 走看看