| |
技术文档>>JAVA>>新手入门>>基础入门>查看文档 |
|
| |
java程序的递归算法,列出某个目录下的所有子目录和文件 |
|
| |
文章作者:未知 文章来源:水木森林 |
|
| |
查看:239次 录入:管理员--2007-11-17 |
|
| |
import java.io.*;
class digui { 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="e://cqq"; system.out.println(strpath);
try { getdir(strpath); } catch(exception e) { } } }
|
|