java zip文件的解压缩(支持中文文件名)
用的apache的ant包,下载导入即可。由于过程比较简单,直接上代码。
代码可直接复制使用。
如果想在android上使用,记得要在AndroidManifest.xml里添加权限:
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Enumeration;
import java.util.zip.ZipException; import org.apache.tools.zip.ZipEntry;
import org.apache.tools.zip.ZipFile; /**
* 可以处理中文文件名
*/
public class jieya { public static void main(String[] args) { /**
* 解压文件
*/
File zipFile = new File("e:/压缩sdhjk.rar"); String path = "e:/zipfile/"; try { unZipFiles(zipFile, path); } catch (Exception e) { System.out.println("解压异常"); }
} /**
* 解压到指定目录
*
* @param zipPath
* @param descDir
* @author isea533
*/
public static void unZipFiles(String zipPath, String descDir) { try { unZipFiles(new File(zipPath), descDir); } catch (Exception e) { e.printStackTrace();
}
} /**
* 解压文件到指定目录
*
* @param zipFile
* @param descDir
* @author isea533
*/
@SuppressWarnings("rawtypes")
public static void unZipFiles(File zipFile, String descDir) { File pathFile = new File(descDir); if (!pathFile.exists()) { pathFile.mkdirs(); } try { ZipFile zip = new ZipFile(zipFile); for (Enumeration entries = zip.getEntries(); entries
.hasMoreElements();) { ZipEntry entry = (ZipEntry) entries.nextElement(); String zipEntryName = entry.getName(); InputStream in = zip.getInputStream(entry); String outPath = (descDir + zipEntryName)
.replaceAll("\\*", "/"); // 判断路径是否存在,不存在则创建文件路径
File file = new File(outPath.substring(0,
outPath.lastIndexOf('/'))); if (!file.exists()) { file.mkdirs(); } // 判断文件全路径是否为文件夹,如果是上面已经上传,不需要解压
if (new File(outPath).isDirectory()) { continue; }
// 输出文件路径信息
System.out.println(outPath); OutputStream out = new FileOutputStream(outPath); byte[] buf1 = new byte[1024]; int len; while ((len = in.read(buf1)) > 0) { out.write(buf1, 0, len); } in.close(); out.close(); }
} catch (ZipException e) { e.printStackTrace(); System.out.println("压缩文件打开异常"); } catch (FileNotFoundException e) { e.printStackTrace();
System.out.println("文件没有找到"); } catch (IOException e) { e.printStackTrace(); System.out.println("io异常");
} System.out.println("******************解压完毕********************");
} }
java zip文件的解压缩(支持中文文件名)的更多相关文章
- java Zip文件解压缩
java Zip文件解压缩 为了解压缩zip都折腾两天了,查看了许多谷歌.百度来的code, 真实无语了,绝大多数是不能用的.这可能跟我的开发环境有关吧. 我用的是Ubuntu14.04,eclips ...
- Servlet 下载文件及支持中文文件名
Sevlet 下载pdf文件 支持中文文件名 package html2pdf.controller; import java.io.File; import java.io.FileInputStr ...
- FullSync不支持中文文件名
FullSync,能实现多种方式.协议的目录同步软件,但不支持中文文件名.
- tomcat支持中文文件名下载
http://blog.csdn.net/wnczwl369/article/details/7483806 Tomcat 是Java开发者使用得较多的一个Web服务器,因为它占用资源小,运行速度快等 ...
- springmvc上传zip文件并解压缩代码示例
<input type="file" id="file" name="file"> spring中的配置: <!-- ...
- 让Tomcat支持中文文件名
--参考链接:http://blog.chinaunix.net/uid-26284395-id-3044132.html 解决问题的核心在于修改Tomcat的配置,在Server.xml文件中添加一 ...
- 使用Java对文件进行解压缩
最近在一个项目中需要对文件进行自动的解压缩,Java提供了这种支持,还是挺好用的. 工具包封装在java.util.zip中. 1.首先是多个文件压缩成一个ZIP文件 思路:用一个ZipOutputS ...
- koala编译scss文件时不支持中文字体的解决方案
第一种方案:在scss文件第一行加上这行代码@charset "utf-8"; 第二种方案: scss文件编译时候使用ruby环境,出现 Syntax error: Invalid ...
- 161012、JAVA读写文件,如何避免中文乱码
1.JAVA读取文件,避免中文乱码. /** * 读取文件内容 * * @param filePathAndName * String 如 c:\\1.txt 绝对路径 * @return boole ...
随机推荐
- 如果解决ubuntu tab键不能提示命令
/bin/sh is symlinked to /bin/dashTo change it, do:sudo rm /bin/shsudo ln -s /bin/bash /bin/sh 原文:htt ...
- 解析Json的谷歌官方方法Gson和阿里巴巴的fastJson方法。
//测试单个json文本 public void testGsonTwo(){ String jsonStr = "{\"id\":100,\"name\&qu ...
- vue js 用nodejs的依赖包 --2016-08-23
今天被nodejs包依赖坑了一下,上次上传的项目突然运行不起来了,原来是package.json中定义了使用最新版本的依赖,而最新版本有可能调整了结构或者改了api,比如vux把flexbox-it ...
- powershell ise好字库和diy配色文件分享
Windows PowerShell ISE (集成脚本环境) 是 Win中自带的脚本编写工具. 在 Windows PowerShell ISE 中,可以在单个基于 Windows 的图形用户界面中 ...
- Cisco IOS debug command reference Command A through D
debug aaa accounting through debug auto-config debug aaa accounting : to display information on acco ...
- 自定义ImageView的MainActivity
package com.baidu.lianximyview; import com.example.myimageview.MyImageView; import android.os.Bundle ...
- dom添加事件
1.语法:document.getElementById('btn').addEventListener 2.可以添加多个EventListener,且不会覆盖 3.移除EventListener, ...
- 如何区别PeekMessage&GetMessage SendMessage&PostMessage
转自http://blog.csdn.net/young0325/article/details/6430664 Peekmessage和Getmessage都是向系统的消息队列中取得消息,不过性质不 ...
- iOS线程
昨天在项目中使用到了以前所没有使用过的线程,今天有时间来简单的学习一下. 一.线程的创建分为三种方法 (id)init; // designated initializer (id)initWithT ...
- 技术分享:逆向分析ATM分离器
文章内容仅供技术交流,请勿模仿操作! 背景(作者) 每一次外出时, Elizabeth和我总是格外的小心,同时把我们身上的钱藏在特殊的皮带上面,这样还不够,我们还采取了“狡兔三窟”的方式来藏身上带的银 ...