Posted on 2007-02-08 09:35
lixw 阅读(210)
评论(0) 编辑 收藏
1 try {
2 String inFilename = "infile";
3 String outFilename = "outfile.zip";
4 FileInputStream in = new FileInputStream(inFilename);
5 ZipOutputStream out = new ZipOutputStream(new FileOutputStream(outFilename));
6 // Add ZIP entry to output stream.
7 out.putNextEntry(new ZipEntry(inFilename));
8 byte[] buf = new byte[1024];
9 int len;
10 while ((len = in.read(buf)) > 0) {
11 out.write(buf, 0, len);
12 }
13 out.closeEntry();
14 out.close();
15 in.close();
16 }catch (IOException e) {}
1 try {
2 String inFilename = "infile.zip";
3 String outFilename = "outfile";
4 ZipInputStream in = new ZipInputStream(new FileInputStream(inFilename));
5 OutputStream out = new FileOutputStream(outFilename);
6 ZipEntry entry;
7 byte[] buf = new byte[1024];
8 int len;
9 if ((entry = in.getNextEntry()) != null) {
10 while ((len = in.read(buf)) > 0) {
11 out.write(buf, 0, len);
12 }
13 }
14 out.close();
15 in.close();
16 } catch (IOException e) {
17 }