import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration; import org.apache.tools.zip.ZipEntry;
import org.apache.tools.zip.ZipFile; /**
* 可以处理中文文件名
*/
public class UnZip2
{
private static final int buffer = 2048; public static void main(String[] args)
{
unZip("D:\\ss\\test.zip");
} public static void unZip(String path)
{
int count = -1;
int index = -1;
String savepath = "";
boolean flag = false; File file = null;
InputStream is = null;
FileOutputStream fos = null;
BufferedOutputStream bos = null; savepath = path.substring(0, path.lastIndexOf("\\")) + "\\"; try
{
ZipFile zipFile = new ZipFile(path); Enumeration<?> entries = zipFile.getEntries(); while(entries.hasMoreElements())
{
byte buf[] = new byte[buffer]; ZipEntry entry = (ZipEntry)entries.nextElement(); String filename = entry.getName();
index = filename.lastIndexOf("/");
if(index > -1)
filename = filename.substring(index+1); filename = savepath + filename; flag = isPics(filename);
if(!flag)
continue; file = new File(filename);
file.createNewFile(); is = zipFile.getInputStream(entry); fos = new FileOutputStream(file);
bos = new BufferedOutputStream(fos, buffer); while((count = is.read(buf)) > -1)
{
bos.write(buf, 0, count );
} fos.close(); is.close();
} zipFile.close(); }catch(IOException ioe){
ioe.printStackTrace();
}
} public static boolean isPics(String filename)
{
boolean flag = false; if(filename.endsWith(".jpg") || filename.endsWith(".gif") || filename.endsWith(".bmp") || filename.endsWith(".png"))
flag = true; return flag;
}
}
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream; public class ImageFileService {
private static final int buffer = 2048; public static void main(String[] args) {
unZip("D:\\YXDoc\\20131212001.zip");
} public static void unZip(String path) {
int count = -1;
int index = -1; String savepath = "";
boolean flag = false;
// 解压路径
savepath = path.substring(0, path.lastIndexOf("\\")) + "\\";
try {
BufferedOutputStream bos = null;
ZipEntry entry = null;
FileInputStream fis = new FileInputStream(path);
ZipInputStream zis = new ZipInputStream(
new BufferedInputStream(fis)); while ((entry = zis.getNextEntry()) != null) {
byte data[] = new byte[buffer];
String temp = entry.getName();
flag = isPics(temp);
if (!flag)
continue;
index = temp.lastIndexOf("/");
if (index > -1)
temp = temp.substring(index + 1);
temp = savepath + temp;
File f = new File(temp);
f.createNewFile();
FileOutputStream fos = new FileOutputStream(f);
bos = new BufferedOutputStream(fos, buffer);
while ((count = zis.read(data, 0, buffer)) != -1) {
bos.write(data, 0, count);
}
bos.flush();
bos.close();
}
zis.close();
} catch (Exception e) {
e.printStackTrace();
}
} public static boolean isPics(String filename) {
boolean flag = false;
if (filename.endsWith(".jpg") || filename.endsWith(".gif")
|| filename.endsWith(".bmp") || filename.endsWith(".png"))
flag = true;
return flag;
}
}
<%@ page language="java" import="java.util.*,java.io.*" pageEncoding="GBK"%>
<%
String path =request.getContextPath();
String basePath =request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
String localPath=(String)request.getAttribute("localPath");
String fileName=(String)request.getAttribute("fileName");
localPath="D://";
fileName="12323.pdf"; %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
</head>
<% out.clear();
out = pageContext.pushBody();
response.setContentType("application/pdf");
try {
String sourcePDFPath =localPath+fileName;
//判断该路径下的文件是否存在
File file = new File(sourcePDFPath);
if (file.exists()){
DataOutputStream ou = new DataOutputStream(response.getOutputStream());
DataInputStream in = new DataInputStream(new FileInputStream(sourcePDFPath));
byte[] b = new byte[2048];
while ((in.read(b)) != -1){
ou.write(b);
ou.flush();
}
in.close();
ou.close();
}else{
out.print(sourcePDFPath + " 文件不存在!");
}
}catch (Exception e) {
out.println(e.getMessage());
}%>
<body>
</body>
</html>

解压Zip的更多相关文章

  1. 【VC++技术杂谈008】使用zlib解压zip压缩文件

    最近因为项目的需要,要对zip压缩文件进行批量解压.在网上查阅了相关的资料后,最终使用zlib开源库实现了该功能.本文将对zlib开源库进行简单介绍,并给出一个使用zlib开源库对zip压缩文件进行解 ...

  2. 通过javascript在网页端解压zip文件并查看压缩包内容

    WEB前端解压ZIP压缩包 web前端解压zip文件有什么用: 只考虑标准浏览器的话, 服务器只要传输压缩包到客户端, 节约了带宽, 而且节约了传输时间, 听起来好像很厉害的说:     如果前端的代 ...

  3. Ubuntu 14 如何解压 .zip、.rar 文件?

    .zip 和 .rar 是Windows下常用的压缩文件,在Ubuntu中如何解压? [解压.zip文件] Ubuntu中貌似已经安装了unzip软件,解压命令如下: unzip ./FileName ...

  4. linux下压缩与解压(zip、unzip、tar)详解

    linux下压缩与解压(zip.unzip.tar)详解 2012-05-09 13:58:39| 分类: linux | 标签:linux zip unzip tar linux命令详解 |举报|字 ...

  5. 解决ubuntu解压zip文件名乱码的问题

    1. 安装7-zip 和 convmv : 命令: sudo apt-get install convmv p7zip-full 2. 解压zip文件: 命令:LANG=C 7z e yourZIPf ...

  6. linux解压zip、bz、bz2、z、gz、tar(解包)

    zip: 压缩: zip [-AcdDfFghjJKlLmoqrSTuvVwXyz$][-b <工作目录>][-ll][-n <字尾字符串>][-t <日期时间>] ...

  7. C# 解压zip压缩文件

    此方法需要在程序内引用ICSharpCode.SharpZipLib.dll 类库 /// <summary> /// 功能:解压zip格式的文件. /// </summary> ...

  8. PHP 的解压缩ZipArchive中的extractTo()方法 LINUX+nginx环境中解压zip时文件丢失的问题

    在项目中要用ZipArchive解压ZIP文件,起初測试环境在WINDOWS平台中,測试通过,换到 LINUX+nginx 的环境中时 就出问题了(ZIP包中有文件和目录一共3百多个文件,大部分是带汉 ...

  9. java 解压 zip 包并删除

    需求是这样的,  在服务器上有 运营上传的zip 包,内容是用户的照片,我需要做的是 获取这些照片上传,并保存到 数据库. 这里面的 上传照片,保存数据库都不难,主要问题是解压zip包,和删除zip ...

  10. Java 解压zip压缩包

    因为最近项目需要批量上传文件,而这里的批量就是将文件压缩在了一个zip包里,然后读取文件进行解析文件里的内容. 因此需要先对上传的zip包进行解压.以下直接提供代码供参考: 1.第一个方法是用于解压z ...

随机推荐

  1. python3--__radd__处理右侧加法

    __radd__处理右侧加法 从严格意义上来讲,前边例子中出现的__add__方法并不支持+运算符右侧使用实例对象.要实现这类表达式,而支持可互换的运算符,可以一并编写__radd__方法.+右侧的对 ...

  2. redis2.3.7安装时出现undefined reference to `clock_gettime'

    (转自:http://blog.csdn.net/qq_28779503/article/details/54844988) undefined reference to `clock_gettime ...

  3. 【Bzoj】1001狼抓兔子(平面图最小割转对偶图最短路)

    YEAH 题目链接 终于做对这道题啦    建图的艰辛难以言表- - 顺便说一句我队列转STL啦 狼抓兔子的地图符合平面图定义,于是将该图转成对偶图并求出对偶图的最短路即可. 这篇博客给了我极大的帮助 ...

  4. Codeforces Round Rockethon 2015

    A. Game 题目大意:A有N1个球,B有N2个球,A每次可以扔1-K1个球,B每次可以扔1-K2个球,谁先不能操作谁熟 思路:.....显然每次扔一个球最优.... #include<ios ...

  5. android源码mk文件里的TARGET_OUT指向哪里?

    android源码核心变量大都在build/core/envsetup.mk中建立 在该文件中,可以找到 TARGET_OUT := $(PRODUCT_OUT)/$(TARGET_COPY_OUT_ ...

  6. [C++] 频谱图中 FFT快速傅里叶变换C++实现

    在项目中,需要画波形频谱图,因此进行查找,不是很懂相关知识,下列代码主要是针对这篇文章. http://blog.csdn.net/xcgspring/article/details/4749075 ...

  7. POJ 2396 有源有汇有上下界可行流问题

    题意:给一个矩阵,给出每行每列之和,附加一些条件,如第i行第j列数必需大于(小于)多少. 思路题解:矩阵模型,模拟网络流,行.列标号为结点,构图,附加s,t,s连行标(容量上下限每行之和(必需以这个 ...

  8. HDU 6149 Valley Numer II(状压DP)

    题目链接 HDU6149 百度之星复赛的题目……比赛的时候并没有做出来. 由于低点只有15个,所以我们可以考虑状压DP. 利用01背包的思想,依次考虑每个低点,然后枚举每个状态. 在每个状态里面任意枚 ...

  9. mysql中进行删除操作时用到not in 导致删除不成功

    delete from tb_news where id not in ( select max(id) From tb_news Group By title ) 刚开始用这条语句删除一直不成功 然 ...

  10. Systemtap examples, Network - 4 Monitoring TCP Packets

    http://blog.163.com/digoal@126/blog/static/16387704020131014104256627/   例子来自tcpdumplike.stp脚本, 当tcp ...