java利用zip解压slpk文件
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();
        }
    }

 

posted on 2019-12-23 14:20  james-roger  阅读(545)  评论(0编辑  收藏  举报