zip file unzip file demo
来源:互联网 发布:linux 安装syslog 编辑:程序博客网 时间:2024/06/10 15:24
some demo here (http://www.example-code.com/java/zip.asp)
make zip file
import java.io.*;
import java.util.zip.*;
class makeZipFile {
public static void main(String[] args) {
if (args.length != 2) {
System.out.println(
"Usage: java makeZipFile [files to be zipped] [filename after zip] ");
return;
}
try {
String filename = args[0];
String zipfilename = args[1];
makeZipFile list = new makeZipFile( );
list.doZip(filename,zipfilename);
} catch (Exception e) {
e.printStackTrace();
}
}
public void doZip(String filename,String zipfilename) {
try {
byte[] buf = new byte[1024];
FileInputStream fis = new FileInputStream(filename);
fis.read(buf,0,buf.length);
CRC32 crc = new CRC32();
ZipOutputStream s = new ZipOutputStream(
(OutputStream)new FileOutputStream(zipfilename));
s.setLevel(6);
ZipEntry entry = new ZipEntry(filename);
entry.setSize((long)buf.length);
crc.reset();
crc.update(buf);
entry.setCrc( crc.getValue());
s.putNextEntry(entry);
s.write(buf, 0, buf.length);
s.finish();
s.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
import java.util.zip.*;
class makeZipFile {
public static void main(String[] args) {
if (args.length != 2) {
System.out.println(
"Usage: java makeZipFile [files to be zipped] [filename after zip] ");
return;
}
try {
String filename = args[0];
String zipfilename = args[1];
makeZipFile list = new makeZipFile( );
list.doZip(filename,zipfilename);
} catch (Exception e) {
e.printStackTrace();
}
}
public void doZip(String filename,String zipfilename) {
try {
byte[] buf = new byte[1024];
FileInputStream fis = new FileInputStream(filename);
fis.read(buf,0,buf.length);
CRC32 crc = new CRC32();
ZipOutputStream s = new ZipOutputStream(
(OutputStream)new FileOutputStream(zipfilename));
s.setLevel(6);
ZipEntry entry = new ZipEntry(filename);
entry.setSize((long)buf.length);
crc.reset();
crc.update(buf);
entry.setCrc( crc.getValue());
s.putNextEntry(entry);
s.write(buf, 0, buf.length);
s.finish();
s.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
package
org.kodejava.example.util.zip;
02.
03.
import
java.util.zip.ZipFile;
04.
import
java.util.zip.ZipEntry;
05.
import
java.util.Enumeration;
06.
import
java.io.*;
07.
08.
public
class
ZipFileUnzipDemo {
09.
public
static
void
main(String[] args) {
10.
String zipname =
"data.zip"
;
11.
12.
try
{
13.
ZipFile zipFile =
new
ZipFile(zipname);
14.
Enumeration enumeration = zipFile.entries();
15.
16.
while
(enumeration.hasMoreElements()) {
17.
ZipEntry zipEntry = (ZipEntry) enumeration.nextElement();
18.
System.out.println(
"Unzipping: "
+ zipEntry.getName());
19.
20.
BufferedInputStream bis =
new
BufferedInputStream(zipFile.getInputStream(zipEntry));
21.
22.
int
size;
23.
byte
[] buffer =
new
byte
[
2048
];
24.
25.
FileOutputStream fos =
new
FileOutputStream(zipEntry.getName());
26.
BufferedOutputStream bos =
new
BufferedOutputStream(fos, buffer.length);
27.
28.
while
((size = bis.read(buffer,
0
, buffer.length)) != -
1
) {
29.
bos.write(buffer,
0
, size);
30.
}
31.
32.
bos.flush();
33.
bos.close();
34.
fos.close();
35.
36.
bis.close();
37.
}
38.
}
catch
(IOException e) {
39.
e.printStackTrace();
40.
}
41.
}
42.
}
- zip file unzip file demo
- How to unzip a zip file which include a folder into a folder
- how to unzip split file
- File Demo
- Flex Documentation Zip File
- Zip File In C#
- python -- zip file
- Zip file too big
- Zip (file format)
- File压缩ZIP文件
- zip/unzip
- zip&unzip
- file is not a zip file 解决方法
- File NIO DEMO
- gcc make file demo
- struts file upload demo
- ant build file demo
- read text file DEMO
- Web测试
- zip压缩以及解压 Compressing and Decompressing Data Using Java APIs
- zip压缩以及解压 Compressing and Decompressing Data Using Java APIs
- 《完美软件》读书笔记11:信息摄取
- 使用volatile关键字的原因
- zip file unzip file demo
- 笔记本共享上网(A有线,B通过无线与A相连)
- 用jquery.validate.js验证表单
- 关于ARM的中断服务程序
- 创建模式:Factory Method工厂模式
- WinXP下搭建virtualbox+ubuntu10.04+LAMP+tomcat6环境小记
- Google Web Toolkit 和 Google App Engine 综合教程 界面篇
- Cadence手工创建PCB元件
- Google Web Toolkit 和 Google App Engine 综合教程 存储篇