zip文件解压工具类
java解压zip文件
- import java.io.BufferedInputStream;
- import java.io.BufferedOutputStream;
- import java.io.File;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.OutputStream;
- import java.util.Enumeration;
- import java.util.zip.CRC32;
- import java.util.zip.CheckedInputStream;
- import org.apache.tools.zip.ZipEntry;
- import org.apache.tools.zip.ZipFile;
- public class MyZipUtil {
- /**
- * 解压zip文件
- * @throws IOException
- */
- public static String unZIP(String zipPath,String outPath ){
- ZipFile zipFile=null;
- try {
- zipFile = new ZipFile(zipPath,"GBK");
- //压缩文件的实列,并设置编码
- //获取压缩文中的所以项
- for(Enumeration<ZipEntry> enumeration = zipFile.getEntries();enumeration.hasMoreElements();)
- {
- OutputStream os = null;
- BufferedOutputStream bos =null;
- InputStream is =null;
- BufferedInputStream bis =null;
- CheckedInputStream cos =null;
- ZipEntry zipEntry = null;
- try {
- zipEntry = enumeration.nextElement();//获取元素
- //排除空文件夹
- if(!zipEntry.getName().endsWith(File.separator))
- {
- System.out.println("正在解压文件:"+zipEntry.getName());//打印输出信息
- //创建解压目录
- File f = new File(outPath);
- //判断是否存在解压目录
- if(!f.exists())
- {
- f.mkdirs();//创建解压目录
- }
- os = new FileOutputStream(outPath+zipEntry.getName().substring(zipEntry.getName().lastIndexOf("/")+1));//创建解压后的文件
- bos = new BufferedOutputStream(os);//带缓的写出流
- is = zipFile.getInputStream(zipEntry);//读取元素
- bis = new BufferedInputStream(is);//读取流的缓存流
- cos = new CheckedInputStream(bis, new CRC32());//检查读取流,采用CRC32算法,保证文件的一致性
- byte [] b = new byte[1024*8];//字节数组,每次读取1024个字节
- //循环读取压缩文件的值
- while(cos.read(b)!=-1)
- {
- bos.write(b);//写入到新文件
- }
- bos.flush();
- os.flush();
- }
- else
- {
- //如果为空文件夹,则创建该文件夹
- new File(outPath+zipEntry.getName()).mkdirs();
- }
- } catch (Exception e) {
- return "1";
- }finally {
- if(cos!=null){
- cos.close();
- }
- if(bis!=null){
- bis.close();
- }
- if(is!=null){
- is.close();
- }
- if(bos!=null){
- bos.close();
- }
- if(os!=null){
- os.close();
- }
- if(zipEntry!=null){
- zipEntry.clone();
- }
- }
- }
- System.out.println("解压完成");
- } catch (IOException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }finally {
- try {
- zipFile.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- return "0";
- }
- }
zip文件解压工具类的更多相关文章
- Zip包解压工具类
最近在做项目的自动检测离线升级,使用到了解压zip包的操作,本着拿来主义精神,搞了个工具类(同事那边拿的),用着还不错. package com.winning.polaris.admin.utils ...
- 文件压缩、解压工具类。文件压缩格式为zip
package com.JUtils.file; import java.io.BufferedOutputStream; import java.io.File; import java.io.Fi ...
- ZIP文件解压
public class DZip { /// <summary> /// 压缩为ZIP文件 /// </summary> public void Zip(string dir ...
- Linux 下 zip 文件解压乱码解决方案,ubuntu16.10亲测可用
文章来源: https://www.zhihu.com/question/20523036 今天邮件中收到了一个压缩文件,解压后却是乱码,从网上也找了几个方法,目前这个方法还是比较可靠的,如下所示: ...
- linux下压缩成zip文件解压zip文件
linux zip命令的基本用法是: zip [参数] [打包后的文件名] [打包的目录路径] linux zip命令参数列表: -a 将文件转成ASCII模式 -F 尝试修复损坏 ...
- Python实现加密的ZIP文件解压(密码已知)
博主在上篇博文介绍了<Python实现加密的RAR文件解压(密码已知)>后,又尝试了ZIP文件的解压方法,下面开始分享. 当ZIP文件的压缩密码已知时,可以通过调用zipfile库进行解压 ...
- Java_压缩与解压工具类
转载请注明出处:http://blog.csdn.net/y22222ly/article/details/52201675 zip压缩,解压 zip压缩与解压主要依靠java api的两个类: Zi ...
- linux下zip文件解压后乱码解决方案
解决办法一,利用pyton来处理 1.vi uzip文件2.复制一下内容(Python) #!/usr/bin/env python # -*- coding: utf-8 -*- # uzip.py ...
- zip文件解压或压缩
<span style="font-size:18px;">/** * lsz */ public final class ZipUtil { /** * 解压zip文 ...
随机推荐
- ACM-ICPC 2018 焦作赛区网络预赛 G Give Candies
There are NNN children in kindergarten. Miss Li bought them NNN candies. To make the process more in ...
- Confluence 6 针对你的数据库类型确定校验 SQL
不同的数据库通常要求不同的 SQL 校验查询.校验查询通常需要尽可能的简单,这个查询在链接从数据库连接池中取出的时候都会被执行一次. 针对不同的数据库类型,我们推荐先的校验查询 SQL: MySQL ...
- verilog-产生axis数据流
首先这是产生aixs数据流的代码 `timescale 1ps/1ps `default_nettype none module axis_switch_0_example_master #( ) ( ...
- LeetCode(124):二叉树中的最大路径和
Hard! 题目描述: 给定一个非空二叉树,返回其最大路径和. 本题中,路径被定义为一条从树中任意节点出发,达到任意节点的序列.该路径至少包含一个节点,且不需要经过根节点. 示例 1: 输入: [1, ...
- nmap 扫描信息收集
1.端口镜像 port Mirroring 功能通过在交换机上或者路由器上,将一个或者多个源端口的数据流量妆发大奥某一个指定的端口来实现对网络的监听,指定端口成为镜像端口或目的端口. 2.ARP攻击捕 ...
- css+js杂记
css的盒子模型分:ie盒子模型和标准盒子模型 区别: 2.选择器 .id选择器(# myid) .类选择器(.myclassname) .标签选择器(div, h1, p) .相邻选择器(h1 + ...
- Python笔记记录
python2和python3的不同: Unicode(统一码.万国码),在3里面可以直接写中文了. python2里rae_input与python3中的input效果一样 在计算机内存中,统一用U ...
- C++ Primer 笔记——模板与泛型编程
1.编译器用推断出的模板参数来为我们实例化一个特定版本的函数. 2.每个类型参数前必须使用关键字class或typename.在模板参数列表中,这两个关键字含义相同,可以互换使用,也可以同时使用. t ...
- The error may exist in com/bjpowernode/dao/StudentDao.xml ### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderExcept
The error may exist in com/bjpowernode/dao/StudentDao.xml### Cause: org.apache.ibatis.builder.Builde ...
- Ubuntu16.04安装vim8
Ubuntu16.04安装vim8 在Ubuntu16.04下编译安装vim8,并配置vim-plug插件管理器,以及安装YouCompleteMe等插件. 安装依赖 sudo apt-get ins ...