伊峰獨居

            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)  編輯  收藏

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


          網站導航:
           
          主站蜘蛛池模板: 锡林浩特市| 磐安县| 平乐县| 罗山县| 兰溪市| 孟连| 炎陵县| 奉化市| 汶川县| 霍城县| 长岭县| 铁岭县| 伊金霍洛旗| 莱西市| 临沧市| 大新县| 新晃| 阳泉市| 凉城县| 滦南县| 曲水县| 青岛市| 太仆寺旗| 泽普县| 麻栗坡县| 宜春市| 邢台县| 丘北县| 太仆寺旗| 罗江县| 池州市| 巧家县| 临江市| 罗田县| 内丘县| 杨浦区| 遂平县| 儋州市| 江川县| 弥渡县| 吴旗县|