伊峰独居

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  30 随笔 :: 30 文章 :: 5 评论 :: 0 Trackbacks

读写ZIP文件

public class TestZip {
 public static void main(String[] args) throws IOException {
  File file = new File("G:\\11.zip");
  FileOutputStream f = new FileOutputStream(file);
  CheckedOutputStream csum = new CheckedOutputStream(f, new Adler32());
  ZipOutputStream zos = new ZipOutputStream(csum);
  BufferedOutputStream bos = new BufferedOutputStream(zos);
  FileInputStream fis = new FileInputStream(
    (new File(
      "E:/eclipse/study/src/java/org/xlincn/study/jdk/io/TestZip.java")));
  zos.putNextEntry(new ZipEntry("test.java"));
  int c;
  while ((c = fis.read()) != -1) {
   bos.write(c);
  }
  fis.close();
  bos.close();
  FileInputStream fi = new FileInputStream(file);
  CheckedInputStream cium = new CheckedInputStream(fi, new Adler32());
  ZipInputStream zin = new ZipInputStream(cium);
  BufferedReader br = new BufferedReader(new InputStreamReader(zin));
  ZipEntry ze;
  while ((ze = zin.getNextEntry()) != null) {
   String s;
   while ((s = br.readLine()) != null) {
    System.out.println(s);
   }
  }
 }
}


递归

static void getFile(String name) throws IOException {
  File file = new File(name);
  File[] f = file.listFiles();
  for (int i = 0; i < f.length; i++) {
   if (f[i].isDirectory()) {
    getFile(f[i].getAbsolutePath());    
   }
   System.out.println("name=" + f[i].getAbsolutePath());   
  }
 }


posted on 2006-09-13 21:14 伊峰 阅读(61) 评论(0)  编辑  收藏

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


网站导航: