当前位置:   article > 正文

linux 如何解压 zip

linux 如何解压 zip

使用unzip命令解压zip文件:

unzip file.zip
  • 1

这将会将file.zip文件解压到当前目录。

使用tar命令解压zip文件:

tar -xf file.zip
  • 1

这将会将file.zip文件解压到当前目录。

使用7z命令解压zip文件:

7z x file.zip
  • 1

这将会将file.zip文件解压到当前目录。

使用python的zipfile模块解压zip文件:

import zipfile
 
with zipfile.ZipFile('file.zip', 'r') as zip_ref:
    zip_ref.extractall()
  • 1
  • 2
  • 3
  • 4

这将会将file.zip文件解压到当前目录。

使用Java的ZipInputStream类解压zip文件:

import java.io.*;
import java.util.zip.*;
 
public class Unzip {
    public static void main(String[] args) {
        String zipFilePath = "file.zip";
        String destinationFolder = "./";
 
        try {
            File destDir = new File(destinationFolder);
            if (!destDir.exists()) {
                destDir.mkdir();
            }
            ZipInputStream zipIn = new ZipInputStream(new FileInputStream(zipFilePath));
            ZipEntry entry = zipIn.getNextEntry();
 
            while (entry != null) {
                String filePath = destinationFolder + File.separator + entry.getName();
                if (!entry.isDirectory()) {
                    extractFile(zipIn, filePath);
                } else {
                    File dir = new File(filePath);
                    dir.mkdir();
                }
                zipIn.closeEntry();
                entry = zipIn.getNextEntry();
            }
            zipIn.close();
            System.out.println("解压完成");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
 
    private static void extractFile(ZipInputStream zipIn, String filePath) throws IOException {
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(filePath));
        byte[] bytesIn = new byte[4096];
        int read;
        while ((read = zipIn.read(bytesIn)) != -1) {
            bos.write(bytesIn, 0, read);
        }
        bos.close();
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44

这段Java代码将会将file.zip文件解压到当前目录。

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号