filecounter.java
来自「一段别人写的LUCENE的东东 拿来大家分享也是给新手用的 但我还有的地方没看懂」· Java 代码 · 共 33 行
JAVA
33 行
package ch14;
import java.io.File;
public class FileCounter {
public static void main(String[] args) throws Exception {
System.out.println(
"目录下共有" + count(new File("c:\\material")) + "个文件");
}
public static int count(File file) throws Exception {
if (file.exists()) {
if (file.isDirectory()) {
String[] files = file.list();
if (files.length == 0) {
return 0;
} else {
int filenum = 0;
for (int i = 0; i < files.length; i++) {
filenum += count(new File(file, files[i]));
}
return filenum;
}
} else {
return 1;
}
} else {
return 0;
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?