posts - 495,  comments - 11,  trackbacks - 0

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

          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函數里面又調用了getDir函數本身
          ????? }
          ???? }
          ???? 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 閱讀(121) 評論(0)  編輯  收藏

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


          網站導航:
           
          主站蜘蛛池模板: 车险| 化德县| 保亭| 泸溪县| 尼木县| 二连浩特市| 阜阳市| 林州市| 革吉县| 宝兴县| 白朗县| 米易县| 任丘市| 鄂托克前旗| 赣榆县| 绥滨县| 武城县| 封开县| 扎鲁特旗| 连城县| 嘉义县| 共和县| 丹寨县| 东阿县| 三原县| 泗水县| 乌鲁木齐县| 小金县| 井陉县| 华宁县| 河间市| 湘潭市| 鞍山市| 仙桃市| 明星| 五原县| 钟祥市| 天峨县| 松潘县| 贵德县| 博乐市|