伊峰獨(dú)居

            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            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 伊峰 閱讀(70) 評論(0)  編輯  收藏

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


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 永仁县| 鹤庆县| 那坡县| 嵊泗县| 永昌县| 肥西县| 伊宁市| 九台市| 镇坪县| 瑞金市| 霍山县| 罗定市| 涟源市| 黄石市| 淅川县| 永顺县| 安岳县| 蓬莱市| 铁力市| 兴城市| 扎赉特旗| 辽中县| 天津市| 桂林市| 鹿邑县| 西乌珠穆沁旗| 普兰县| 旬阳县| 霍山县| 桂平市| 大方县| 山西省| 临澧县| 五家渠市| 临桂县| 潞西市| 正安县| 灵山县| 上杭县| 肇州县| 长兴县|