posts - 495,  comments - 11,  trackbacks - 0

          //用遞歸算法列出某個(gè)目錄下的所有子目錄和文件

          import java.io.*;

          class DiGuiGetDir
          {
          static void getDir(String strPath) throws Exception
          {
          ?? try
          ?? {
          ??? File f=new File(strPath);
          ??? if(f.isDirectory())
          ??? {
          ???? File[] fList=f.listFiles();
          ???? for(int j=0;j<fList.length;j++)
          ???? {
          ????? if(fList[j].isDirectory())
          ????? {
          ?????? System.out.println(fList[j].getPath());
          ?????? getDir(fList[j].getPath()); //在getDir函數(shù)里面又調(diào)用了getDir函數(shù)本身
          ????? }
          ???? }
          ???? for(int j=0;j<fList.length;j++)
          ???? {
          ????? if(fList[j].isFile())
          ????? {
          ?????? System.out.println(fList[j].getPath());
          ????? }

          ???? }
          ??? }
          ?? }
          ?? catch(Exception e)
          ?? {
          ??? System.out.println("Error: " + e);
          ?? }
          }

          public static void main(String[] args)
          {
          ?? String strPath="d:\\Download";
          ?? System.out.println(strPath);

          ?? try
          ?? {
          ??? getDir(strPath);
          ?? }
          ?? catch(Exception e)
          ?? {

          ?? }
          }
          }

          posted on 2007-05-19 10:45 jadmin 閱讀(122) 評(píng)論(0)  編輯  收藏

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


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 简阳市| 鹤庆县| 敖汉旗| 信丰县| 龙州县| 吕梁市| 廉江市| 榆树市| 湖北省| 镇远县| 乌海市| 固安县| 福建省| 娄底市| 郴州市| 丹寨县| 石林| 瓦房店市| 衡南县| 泰州市| 赤城县| 顺义区| 玉溪市| 岳阳县| 涟水县| 贵德县| 小金县| 广饶县| 达日县| 禹城市| 曲阳县| 金川县| 馆陶县| 辰溪县| 琼结县| 调兵山市| 天峨县| 潼关县| 阿克苏市| 扬中市| 永吉县|