http://supanccy2013.iteye.com/admin/blogs/new
package main;
import java.io.File;
public class Main
{
public static void main(String[] args) throws Exception
{
// 递归显示C盘下所有文件夹及其中文件
File root = new File("d:/temp");
showDir(root);
}
public static void showDir(File dir) {
File[] fstr = dir.listFiles();
if(fstr == null || (fstr != null && fstr.length==0)){ //判断一下是否为空
return;
}
for(File file : fstr) {
if(file.isDirectory())
showDir(file);
else if(file.isFile() && file.getName().endsWith(".txt"))
System.out.println(file);
}
}
}
http://zhidao.baidu.com/link?url=AqtyzFp2Ja6Z14-FV58ar4pbRMk9NUCn7KyUp_wG7uFZ6dpkXKOFU3bEYup9fp4Zov8dHictEoY6FQ8WPiMZmq
package main;
import java.io.File;
public class Main
{
public static void main(String[] args) throws Exception
{
// 递归显示C盘下所有文件夹及其中文件
File root = new File("d:/temp");
showDir(root);
}
public static void showDir(File dir) {
File[] fstr = dir.listFiles();
if(fstr == null || (fstr != null && fstr.length==0)){ //判断一下是否为空
return;
}
for(File file : fstr) {
if(file.isDirectory())
showDir(file);
else if(file.isFile() && file.getName().endsWith(".txt"))
System.out.println(file);
}
}
}
http://zhidao.baidu.com/link?url=AqtyzFp2Ja6Z14-FV58ar4pbRMk9NUCn7KyUp_wG7uFZ6dpkXKOFU3bEYup9fp4Zov8dHictEoY6FQ8WPiMZmq
本文介绍了一个简单的Java程序,该程序能够递归地遍历指定目录(本例中为D盘temp文件夹),并列出所有的.txt文件。通过递归的方式深入每一个子目录进行搜索。
1039

被折叠的 条评论
为什么被折叠?



