JSP解压ZIP压缩文件
2012-11-16 15:18
330 查看
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.io.*,java.util.zip.*"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
try {
ZipInputStream in = new ZipInputStream(new FileInputStream(application.getRealPath("/") + "1.zip"));
ZipEntry entry = null;
while ((entry = in.getNextEntry()) != null) {
String entryName = entry.getName();
if (entry.isDirectory()) {
File file = new File(application.getRealPath("/") + entryName);
file.mkdirs();
System.out.println("创建文件夹" + entryName);
} else {
FileOutputStream os = new FileOutputStream(application.getRealPath("/") + entryName);
// Transfer bytes from the ZIP file to the output file
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
os.write(buf, 0, len);
}
os.close();
in.closeEntry();
}
}
} catch (IOException e) {
}
out.println("解压文件成功!");
%>
</body>
</html>
<%@ page import="java.io.*,java.util.zip.*"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
try {
ZipInputStream in = new ZipInputStream(new FileInputStream(application.getRealPath("/") + "1.zip"));
ZipEntry entry = null;
while ((entry = in.getNextEntry()) != null) {
String entryName = entry.getName();
if (entry.isDirectory()) {
File file = new File(application.getRealPath("/") + entryName);
file.mkdirs();
System.out.println("创建文件夹" + entryName);
} else {
FileOutputStream os = new FileOutputStream(application.getRealPath("/") + entryName);
// Transfer bytes from the ZIP file to the output file
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
os.write(buf, 0, len);
}
os.close();
in.closeEntry();
}
}
} catch (IOException e) {
}
out.println("解压文件成功!");
%>
</body>
</html>
相关文章推荐
- JSP解压ZIP压缩文件
- JSP解压ZIP压缩文件
- JSP解压ZIP压缩文件
- c# 动态操作 zip\rar 文件,压缩解压组件使用
- 使用 ZLib 压缩/解压 ZIP 文件
- Linux 下压缩与解压.zip和.rar及.7z文件
- [随笔]Linux下常用压缩文件(*.tar.gz *.tar.xz *.zip ...)的解压方法
- java 压缩/解压 zip 多个文件和文件夹
- golang zip 压缩,解压(含目录文件)
- java解压zip或rar压缩文件(有源码和jar包以及对中文乱码的处理方法)
- 【Delphi】从内存读取或解压压缩文件(RAR、ZIP、TAR、GZIP等)(三)
- Zip压缩文件 与 解压 (MFC 文件操作 四 )
- 解压zip跟rar压缩文件
- c# 文件压缩zip或将zip文件解压
- java实现将ZIP压缩文件解压的工具类
- C#压缩解压zip 文件
- Ionic.Zip.dll文件压缩和解压
- android通过org.apache.tools.zip解压zip压缩文件,支持中文名
- .zip文件解压、压缩
- java实现将ZIP压缩文件解压的工具类