您的位置:首页 > 编程语言 > Java开发

递归算法 列出给定目录下的文件/java描述

2007-08-14 10:18 337 查看
/*
文件名: DiGui.java
描述: 列出某个目录下面的所有子目录
*/

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("d/t" + fList[j].getPath());
getDir(fList[j].getPath()); }
if (fList[j].isFile()) {
System.out.println("f/t" + fList[j].getPath());
}
}

}
} catch (Exception e) {
System.out.println("Error: " + e);
}

}

public static void main(String[] args) {
String strPath = "e://java//workspace//MyJava//";
try {
getDir(strPath);
} catch (Exception e) {

}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: