日期:2014-05-20  浏览次数:20636 次

遍历指定文件夹的代码,大家也把自己贴上来吧,希望前辈们也进来指点一下,我想学习学习,提建议的,贴代码的都有分。
/**
  *   @(#)Test.java   1.0   2007-07-31
  *   @author   Yuan
  *   @version   1.0
  *   JDK   version   used   1.6.0
  *   */

package   com.sqxy.tools;

import   java.io.File;
import   java.util.List;
import   java.util.ArrayList;

/**
  *   FileTool
  *   */

public   class   FileTool   {
       
       
        //List <File>   directoryList   is   used   to   save   all   directories.        
        private   List <File>   directoryList   =   new   ArrayList <File> ();
       
        //List <File>   fileList   is   used   to   save   all   files.
        private   List <File>   fileList   =   new   ArrayList <File> ();

        /**
          *   @return   the   list   of   all   directories   in   the   directory.
          *   */
        public   List <File>   getDirectoryList()   {
                return   directoryList;
        }

        /**
          *   @return   the   list   of   all   files   in   the   directory.
          *   */
        public   List <File>   getFileList()   {
                return   fileList;
        }
       
        /**
          *   If   the   File   appointed   is   file,
          *   then   print   its   attributes.
          *  
          *   If   the   File   appointed   is   directory,
          *   then   traverse   the   appointed,
          *   add   all   directories   and   files   in   the   directory   to   their   own   list.
          *  
          *   @param   name         the   name   of   the   file   or   path.
          *   */
        public   void   loadFile(String   name)
        {
                //isBeginning用于标记是否是第一次循环
                boolean   isBeginning   =   true;
                File   file   =   new   File(name);
               
                if   (file.isDirectory())