zip 包解压缩  记录

zip 包解压缩 

ZipInputStream zipInput = new ZipInputStream(inputStream, Charset.forName("GBK"));
                //读取一个目录
                ZipEntry nextEntry = zipInput.getNextEntry();
                String outPath = appConfig.getTmpPath() + System.currentTimeMillis() + File.separator;
                File outFile = new File(outPath);
                if (!outFile.exists()) {
                    outFile.mkdirs();
                }
                //不为空进入循环
                while (nextEntry != null) {
                    String name = nextEntry.getName();
                    File file = new File(outPath + File.separator + name);
                    fileProber(file);
                    //如果是目录,创建目录
                    if (name.endsWith("/")) {
                        file.mkdirs();
                    } else {
                        file.createNewFile();
                        //文件则写入具体的路径中
                        FileOutputStream fileOutputStream = new FileOutputStream(file);
                        BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(fileOutputStream);
                        int n;
                        byte[] bytes = new byte[1024];
                        while ((n = zipInput.read(bytes)) != -1) {
                            bufferedOutputStream.write(bytes, 0, n);
                        }
                        //关闭流
                        bufferedOutputStream.close();
                        fileOutputStream.close();
                    }
                    //关闭当前
                    zipInput.closeEntry();
                    //读取下一个目录,作为循环条件
                    nextEntry = zipInput.getNextEntry();
                }
 public static void fileProber(File dirFile) throws Exception {
        File parentFile = dirFile.getParentFile();
        if (!parentFile.exists()) {
            fileProber(parentFile);
            parentFile.mkdirs();
        }
    }

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 在Linux中,可以使用unzip命令来解压缩zip。具体命令格式如下: ``` unzip filename.zip ``` 其中,filename.zip为要解压缩zip文件名。执行该命令后,zip将会被解压缩到当前目录下。如果要将zip解压缩到指定目录下,可以使用如下命令: ``` unzip filename.zip -d /path/to/directory ``` 其中,/path/to/directory为指定的目录路径。 ### 回答2: 在Linux中,我们可以使用unzip命令来解压缩zip。unzip命令是一个非常常用的命令,可以解压缩各种类型的压缩文件,zip格式。 要解压缩一个zip,我们可以使用以下命令格式: unzip [选项] 压缩文件名.zip 其中,[选项]是可选的,可以为一些附加参数,可以根据需要进行指定。 常用的一些选项括: -n:不覆盖已存在的文件; -o:解压缩时覆盖已存在的文件; -d 目录名:将压缩文件解压缩到指定的目录中。 例如,如果我们有一个名为example.zip的压缩文件,并且想要解压缩到当前目录中,可以使用以下命令: unzip example.zip 这将会将example.zip解压缩到当前目录中。 如果我们想要将example.zip解压缩到一个指定的目录中,可以使用-d选项,例如: unzip example.zip -d /path/to/directory 这将会将example.zip解压缩到/path/to/directory目录中。 总结起来,解压缩zip的命令是unzip,通过指定选项和压缩文件名来实现解压缩操作。 ### 回答3: 在Linux系统中解压缩zip的命令是"unzip"。使用该命令可以将zip文件解压缩并提取其中的文件。 基本的zip解压命令如下: unzip [选项] 压缩.zip 选项: -e:将解压缩的文件提取到当前目录(不含目录结构) -d 目录:将解压缩的文件提取到指定目录 -o:不询问直接覆盖已存在的文件 -q:静默模式,不显示解压缩的详细信息 -v:显示解压缩的详细信息 -f:测试zip文件是否损坏 -p:将解压缩的文件输出到标准输出,可以通过重定向来保存为文件 例如,要解压缩名为"example.zip"的zip,将其中的文件提取到当前目录,可以使用以下命令: unzip example.zip 如果要将文件提取到指定目录"destination",可以使用以下命令: unzip example.zip -d destination 通常情况下,Linux系统都会预装unzip命令,可以直接在终端中使用。如果系统没有预装该命令,可以通过管理器来安装,例如在Ubuntu上使用apt-get: sudo apt-get install unzip 总之,通过unzip命令可以在Linux系统中解压缩zip,提取其中的文件,并且可以根据需求使用不同的选项来控制解压缩过程。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值