JAVA 解压文件
来源:互联网 发布:ubuntu 安装apache 编辑:程序博客网 时间:2024/05/01 19:42
转自:http://blog.csdn.net/isea533/article/details/7995472
//先下载zip.jar,然后执行以下代码
public class UnZip {
/**
* 解压到指定目录
* @param zipPath
* @param descDir
* @author isea533
*/
public static void unZipFiles(String zipPath,String descDir)throws IOException{
unZipFiles(new File(zipPath), descDir);
}
/**
* 解压文件到指定目录
* @param zipFile
* @param descDir
* @author isea533
*/
@SuppressWarnings("rawtypes")
public static void unZipFiles(File zipFile,String descDir)throws IOException{
File pathFile = new File(descDir);
if(!pathFile.exists()){
pathFile.mkdirs();
}
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();
}
System.out.println("******************解压完毕********************");
}
public static void main(String[] args) {
/**
* 解压文件
*/
File zipFile = new File("c:/test.zip");
String path = "c:/test/";
try {
UnZip.unZipFiles(zipFile, path);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
0 0
- Java解压zip文件
- Java 解压文件
- java 文件解压
- java解压文件失败
- Java解压Jar文件
- JAVA 压缩解压文件
- java解压gz文件
- java解压rar文件
- java文件解压
- java解压rar文件
- JAVA 解压文件
- Java 解压文件
- Java解压文件
- zip解压文件java
- java-zip解压文件
- java解压Apk文件
- JAVA解压ZIP文件
- JAVA文件压缩、解压
- java架构师喜欢问的问题
- Mac下配置tomcat
- 另外一篇字符编码的好文章
- poj3258
- 个人各国法国恢复规划
- JAVA 解压文件
- LQX的作业
- redis读写分离下的高可用设计与实现(上)
- 不小心把手机里的照片删了怎么恢复
- 一键合成APK
- 拼装html字符串的最快方法
- ConfigurationSection类使用心得
- SQL数据库面试题以及答案
- 数学之美系列 布隆过滤器(Bloom Filter)