java 学习

软件开发相关方面的学习

BlogJava 首页 新随笔 联系 聚合 管理
  33 Posts :: 1 Stories :: 5 Comments :: 0 Trackbacks

import java.io.*;
import java.util.zip.*;
public class Example4 {
   //writing a zip archive
   static ZipOutputStream myZOS;

   public static void main(String args[]) {
      myZOS = new ZipOutputStream (
                              new BufferedOutputStream(
                                       new FileOutputStream("code.zip")));
      writeOneFile("Example1.java");
      writeOneFile("Example2.java");
      writeOneFile("Example3.java");
      myZOS.close();
   }

   static void writeOneFile(String name) throws IOException {
      ZipEntry myZE = new ZipEntry(name);
      myZOS.putNextEntry(myZE);
      
      BufferedReader myBR = new BufferedReader(new FileReader(name));
      int c;
      while((c = myBR.read()) != -1)//read a char until EOF
           myZOS.write(c);
       myBR.close();                                                       
   }
}

posted on 2006-08-03 21:48 zxf 阅读(350) 评论(0)  编辑  收藏 所属分类: java

只有注册用户登录后才能发表评论。


网站导航: