public static void main(String[] args) {
        File file = new File("C:\\Users\\Administrator\\Desktop\\aa\\sdcbz.slpk");//当前压缩文件
        ZipInputStream zin;//创建ZipInputStream对象
        try {
            ZipFile zipFile = new ZipFile(file);//创建压缩文件对象
            zin = new ZipInputStream(new FileInputStream(file));//实例化对象,指明要解压的文件
            ZipEntry entry ;
            while (((entry=zin.getNextEntry())!=null)&& !entry.isDirectory()){//如果entry不为空,并不在同一个目录下
                File tmp = null;
                tmp = new File("C:\\Users\\Administrator\\Desktop\\aa\\" + entry.getName());//解压出的文件路径
                if (!tmp.exists()){//如果文件不存在
                    tmp.getParentFile().mkdirs();//创建文件父类文件夹路径
                    OutputStream os = new FileOutputStream(tmp);//将文件目录中的文件放入输出流
                    //用输入流读取压缩文件中制定目录中的文件
                    InputStream in = zipFile.getInputStream(entry);
                    int count = 0;
                    while ((count = in.read())!=-1){//如有输入流可以读取到数值
                        os.write(count);//输出流写入
                    }
                    os.close();
                    in.close();
                }
                zin.closeEntry();
                System.out.println(entry.getName()+"解压成功");
            }
            zin.close();

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

 

相关文章:

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