伊峰獨居

            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 伊峰 閱讀(72) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 青州市| 湄潭县| 大悟县| 健康| 达州市| 沅陵县| 古浪县| 湘乡市| 江城| 灵璧县| 迁西县| 孟村| 闽侯县| 肥西县| 黎城县| 民丰县| 宜宾县| 嵊泗县| 秭归县| 介休市| 基隆市| 南江县| 那曲县| 深水埗区| 清涧县| 东源县| 和林格尔县| 榆社县| 西昌市| 辰溪县| 富川| 卢氏县| 双柏县| 长垣县| 钦州市| 尖扎县| 津南区| 临西县| 伊川县| 南昌市| 汉川市|