unzip.java
来自「实现PKI/CA的数字签名部分」· Java 代码 · 共 42 行
JAVA
42 行
package zipfile;
import java.io.*;
import java.util.zip.*;
public class Unzip {
public static void UnZip(String unzipfile) {
try {
File olddirec = new File(unzipfile); //解压缩的文件路径(为了获取路径)
ZipInputStream zin = new ZipInputStream(new FileInputStream(unzipfile));
ZipEntry entry;
//创建文件夹
while ( (entry = zin.getNextEntry()) != null){
if (entry.isDirectory()) {
File directory = new File(olddirec.getParent(), entry.getName());
if (!directory.exists())
if (!directory.mkdirs())
System.exit(0);
zin.closeEntry();
}
if (!entry.isDirectory()) {
File myFile = new File(entry.getName());
FileOutputStream fout = new FileOutputStream("D:\\soft\\YSF\\"+myFile.getPath());
DataOutputStream dout = new DataOutputStream(fout);
byte[] b = new byte[1024];
int len = 0;
while ( (len = zin.read(b)) != -1) {
dout.write(b, 0, len);
}
dout.close();
fout.close();
zin.closeEntry();
}
}
}
catch (IOException e) {
e.printStackTrace();
System.out.println(e);
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?