赞
踩
使用unzip命令解压zip文件:
unzip file.zip
这将会将file.zip文件解压到当前目录。
使用tar命令解压zip文件:
tar -xf file.zip
这将会将file.zip文件解压到当前目录。
使用7z命令解压zip文件:
7z x file.zip
这将会将file.zip文件解压到当前目录。
使用python的zipfile模块解压zip文件:
import zipfile
with zipfile.ZipFile('file.zip', 'r') as zip_ref:
zip_ref.extractall()
这将会将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(); } }
这段Java代码将会将file.zip文件解压到当前目录。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。