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

public static Map<String,Object> 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<String,Object> readmap = new HashMap<String,Object>();
List<String> 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;
}
阅读更多 登录后自动展开
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页