解压zip文件,并按行读取读取,返回list

public static Map zipReadMethodTest2(BufferedInputStream file) throws Exception{
ZipInputStream zipIn = new ZipInputStream(file,Charset.forName("GBK"));
InputStreamReader read = new InputStreamReader(zipIn);
ZipEntry zeEnt = null;
//ZipFile zf = new ZipFile(file);
Map readmap = new HashMap();
List list = new ArrayList<>();
BufferedReader bufferedReader = new BufferedReader(read);
while ((zeEnt=zipIn.getNextEntry())!=null) {
System.out.println("Extracting: " + zeEnt);
if(!zeEnt.isDirectory()){
/*int count;
                byte data[] = new byte[1024];


                FileOutputStream fos = new
                                       FileOutputStream("F:/"+zeEnt.getName());
                BufferedOutputStream dest = new BufferedOutputStream(fos, 1024);
                
                
                while ((count = zipIn.read(data, 0, 1024))
                                != -1) {
                    dest.write(data, 0, count);
                }*/
                
                //将文件按行读取,放入到list中
                
                
                String lineTxt = null;
                while((lineTxt = bufferedReader.readLine()) != null){
                    //System.out.println(lineTxt);
                    //String b=aa.substring(aa.length()-n,aa.length());
                list.add(lineTxt.substring(lineTxt.length()-20, lineTxt.length()));
                }
                
                //read.close();
                readmap.put("list", list);
               // bufferedReader.close();
               // dest.flush();
               // dest.close();

System.out.println("读到了");
}
}

System.out.println(list.size());
read.close();
bufferedReader.close();
zipIn.close();
return readmap;
}

你可能感兴趣的:(解压zip文件,并按行读取读取,返回list)