javaunzip⽅法
第⼀次⽅式是apache的zip包
<dependency>
<groupId>org.apachemons</groupId>
<artifactId>commons-compress</artifactId>
<version>1.16</version>
</dependency>
ZipFile zipFile = null;
int BUFFER_SIZE=1024;
try {
zipFile=new ZipFile(zip);
Enumeration<ZipArchiveEntry> entries = Entries();
ZipArchiveEntry entry = null;
while (entries.hasMoreElements()) {
entry = Element();
if (entry.isDirectory()) {
File directory = new File(zipPath, Name());
directory.mkdirs();
} else {
File file = new File(zipPath, Name());
if (!ParentFile().exists()) {
}
InputStream is = InputStream(entry);
OutputStream os = new BufferedOutputStream(new FileOutputStream(file), BUFFER_SIZE);
IOUtils.closeQuietly(os);
IOUtils.closeQuietly(is);
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
zipFile.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
第⼆种是⽤zip4j
<dependency>
<groupId>net.lingala.zip4j</groupId>
<artifactId>zip4j</artifactId>
<version>1.3.2</version>
</dependency>
public static void main(String[] args) {
String file1 = "d:\\worktemp\\hfhhByUnitPaper.zip";
String target = "D:\\worktemp";
mkdirs方法
String password = "password";
try {
ZipFile zipFile = new ZipFile(file1);
//zipFile.se
if (zipFile.isEncrypted()) {
zipFile.setPassword(password);
}
} catch (ZipException e) {
e.printStackTrace();
}
}
不建设⽤apache的ZipArchiveInputStream,会有很多问题..详细情况可以参考源码中的说明..

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。