zoukankan      html  css  js  c++  java
  • 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();
            }
        }
  • 相关阅读:
    mysql无法导出表内容
    mysql回收用户权限
    mysql跳过授权表进入服务
    数组forEach函数
    数组的filter函数
    无符号右移运算
    按位非运算符
    TP5页面跳转与重定向
    thinkphp5 $this->fetch()
    linux下vi命令修改文件及保存的使用方法
  • 原文地址:https://www.cnblogs.com/james-roger/p/12083524.html
Copyright © 2011-2022 走看看