博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
JAVA解压Zip格式文件的代码
阅读量:2024 次
发布时间:2019-04-28

本文共 1651 字,大约阅读时间需要 5 分钟。

代码如下,已经测试:

private static void unzipFile(final String dir, final File zf)    {        File file = null;        try        {            ZipFile zipFile = new ZipFile(zf.toString());            Enumeration
entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = (ZipEntry)entries.nextElement(); String filename = entry.getName(); //目录,产生后返回。 if (entry.isDirectory()) { file = new File(dir + File.separator +filename); file.mkdirs(); continue; } //确实有这种情况。 else if (filename.indexOf('/') >= 0) { String subdir = filename.substring(0, filename.lastIndexOf('/')); file = new File(dir + File.separator +subdir); file.mkdirs(); } file = new File(dir + File.separator +filename); file.createNewFile(); InputStream is = zipFile.getInputStream(entry); FileOutputStream fos = new FileOutputStream(file); int count = 0; byte buf[] = new byte[4096]; while ((count = is.read(buf)) > 0) { fos.write(buf, 0, count); } fos.close(); is.close(); } zipFile.close(); } catch (Exception e) { System.out.println(dir+", "+zf+", "+file); e.printStackTrace(); } }

 

转载地址:http://xvuaf.baihongyu.com/

你可能感兴趣的文章
170406回顾-SQL Server的smalldatetime类型比较
查看>>
Flask:静态文件&模板(0.1)
查看>>
Python解决八皇后问题的代码【解读】
查看>>
使用免安装压缩包安装MySQL
查看>>
Flask:初次使用Blueprints
查看>>
Python基础:内置函数
查看>>
Windows安装pycrypto失败记录
查看>>
使用OpenSSL自建CA + Nginx配置HTTPS
查看>>
使用Eclipse运行第一个Go程序
查看>>
CSP考试 2014年03月第1题 相反数 C语言实现
查看>>
CSP考试 2016年4月第1题 折点计数 C语言实现
查看>>
SQL Server 2008 ——关系
查看>>
Sql Server 2008-闲聊
查看>>
软工文档——未来软件的生命
查看>>
C#基础总结
查看>>
【Linux Is Not Unix 】虚拟机下CentOS配置ip三种方法的区别
查看>>
【时间管理】优秀是选择的结果
查看>>
【Linux Is Not Unix】Linux如何增加和修改SSH端口号
查看>>
win10 CPU占用率过高 经常100%
查看>>
.net中获取MD5码
查看>>