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. Python第三方库之openpyxl(6)

    Python第三方库之openpyxl(6) 折线图 折线图允许在固定轴上绘制数据,它们类似于散列图,主要的区别在于,在折线图中,每个数据序列都是根据相同的值绘制的,不同的轴可以用于辅助轴,与条形图类 ...

  2. 图论trainning-part-1 H. Qin Shi Huang's National Road System

    H. Qin Shi Huang's National Road System Time Limit: 1000ms Memory Limit: 32768KB 64-bit integer IO f ...

  3. nginx反向代理,负载均衡,动静分离,rewrite地址重写介绍

    一.rewrite地址重写 地址转发后客户端浏览器地址栏中的地址显示是不变的,而地址重写后地址栏中的地址会变成正确的地址. 在一次地址转发过程中只会产生一次网络请求,而一次地址重写产生两次请求. 地址 ...

  4. BASH重定向问题

    APUE 3.5关于重定向有个容易迷惑人的问题: ./a.out > outfile 2>&1 ./a.out 2>&1 > outfile 问两者区别? in ...

  5. excel截取某个字符之前的值

    1.find为查找函数,返回字符的位置,语法find(查找字符,被查字符或者单元格) 找到第一个-位置 2.left,字符截取函数,从左边开始,left(被截取的字符,个数)

  6. Unity3D for iOS初级教程:Part 2/3

    转自Unity3D for iOS 这篇文章还可以在这里找到 英语 Learn how to use Unity to make a simple 3D iOS game! 这篇教材是来自教程团队成员 ...

  7. 算法复习——单调队列(sliding windows,ssoi)

    题目: 题目描述 给你一个长度为 N 的数组,一个长为 K 的滑动的窗体从最左移至最右端,你只能见到窗口的 K 个整数,每次窗体向右移动一位,如下表:

  8. 【2018.11.23】2018WCTest(7)

    向已退役学长致敬! 题目&他的题解 T1 一道睿智题目,正常思路就是时空复杂度均为 $O(n\times 32768)$ 的背包.这个做法不被卡时间却被卡空间,其实就是想让你离线处理询问,然后 ...

  9. Linux命令——top

    top命令可以实时动态地查看系统的整体运行情况,是一个综合了多方信息监测系统性能和运行信息的实用工具.通过top命令所提供的互动式界面,用热键可以管理. 语法 top(选项) 选项 -b:以批处理模式 ...

  10. OpenJ_Bailian3375

    Farmer John has decided to reward his cows for their hard work by taking them on a tour of the big c ...