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;
	}
}

  

相关文章:

  • 2021-08-01
  • 2021-08-16
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-11
  • 2022-12-23
  • 2021-10-08
  • 2022-12-23
  • 2021-08-02
  • 2021-09-07
  • 2021-07-01
相关资源
相似解决方案