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();
            }
        }
  • 相关阅读:
    设计模式(四)多例模式
    python之decode、encode及codecs模块
    python pyqt
    python读取命令行参数的方法
    python urllib、urlparse、urllib2、cookielib
    百度文档免费下载
    python之控制台(console)颜色显示
    python修改注册表
    python之爬虫
    xmlns和xsi之schemaLocation
  • 原文地址:https://www.cnblogs.com/james-roger/p/12083524.html
Copyright © 2011-2022 走看看