递归算法

来源:互联网 发布:安卓双系统软件 编辑:程序博客网 时间:2024/06/14 23:42

递归算法
注:递归,就是在运行的过程中调用自己。

代码如下:

File f=new File("C:\\Users\\Administrator\\Desktop\\a");    if(f.isDirectory()){       //文件夹       //列出该文件夹下所有的文件      File fs[]=f.listFiles();        if(fs.length>0){                //有子目录或者子文件                for (File file : fs) {                    if(file.isDirectory()){                        read(file);                    }else{            //打印文件路径                                  System.out.println(file.getAbsolutePath());                        }                }            }else{                //没有子目录或者子文件            System.out.println(f.getAbsolutePath());            }        }else{            //打印文件路径            System.out.println(f.getAbsolutePath());        }