Java 实例 - 遍历指定目录下的所有目录
Java 教程
· 2019-02-11 07:59:27
以下实例演示了如何使用 File 类的 list 方法来遍历指定目录下的所有目录:
Main.java 文件
import java.io.*;
class Main {
public static void main(String[] args) {
File dir = new File("F:");
File[] files = dir.listFiles();
FileFilter fileFilter = new FileFilter() {
public boolean accept(File file) {
return file.isDirectory();
}
};
files = dir.listFiles(fileFilter);
System.out.println(files.length);
if (files.length == 0) {
System.out.println("目录不存在或它不是一个目录");
}
else {
for (int i=0; i< files.length; i++) {
File filename = files[i];
System.out.println(filename.toString());
}
}
}
}
以上代码运行输出结果为:
14 F:\C Drive Data Old HDD F:\Desktop1 F:\harsh F:\hharsh final F:\hhhh F:\mov F:\msdownld.tmp F:\New Folder F:\ravi F:\ravi3 F:\RECYCLER F:\System Volume Information F:\temp F:\work
点击查看所有 Java 教程 文章: https://www.codercto.com/courses/l/12.html
Flexible Rails
Peter Armstrong / Manning Publications / 2008-01-23 / USD 44.99
Rails is a fantastic tool for web application development, but its Ajax-driven interfaces stop short of the richness you gain with a tool like Adobe Flex. Simply put, Flex is the most productive way t......一起来看看 《Flexible Rails》 这本书的介绍吧!