`
ghost_fly
  • 浏览: 108728 次
  • 性别: Icon_minigender_1
  • 来自: 长沙
社区版块
存档分类
最新评论

打印目录文件名

    博客分类:
  • JAVA
 
阅读更多
mport   java.io.*;   
    
  public   class   FindDirectories   
  {     public   static   void   main(String[]   args)   
        {     if   (args.length   ==   0)   args   =   new   String[]   {   ".."   };   
    
              try   
              {     File   pathName   =   new   File(args[0]);   
                    String[]   fileNames   =   pathName.list();   
    
                    for   (int   i   =   0;   i<fileNames.length;   i++)   
                    {     File   tf   =   new   File(pathName.getPath(),     
                                fileNames[i]);   
                          if   (tf.isDirectory())   
                          {     System.out.println(tf.getCanonicalPath());   
                                main(new   String   []   {   tf.getPath()   });   
                          }   
                    }   
              }   
              catch(IOException   e)   
              {     System.out.println("Error:   "   +   e);   
              }   
        }   
  }   
  //代码中没有用到的方法getCanonicalFile()是显示全部规范化的文件名,具体用法请见api     
    

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics