s-day08-练习_打印指定目录下所有的txt文件
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package com.inmind.digui02;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/*
|
||||
练习_打印指定目录下所有的txt文件
|
||||
*/
|
||||
public class Test12 {
|
||||
public static void main(String[] args) {
|
||||
File file = new File("D:\\io_test");
|
||||
getFiles(file);
|
||||
}
|
||||
|
||||
public static void getFiles(File file) {
|
||||
if (file.isFile()) {
|
||||
return;//文件就不用遍历
|
||||
}
|
||||
File[] files = file.listFiles();
|
||||
for (File f : files) {
|
||||
if (f.isDirectory()) {
|
||||
getFiles(f);
|
||||
} else {
|
||||
//文件判断
|
||||
String name = f.getName();
|
||||
if (name.endsWith(".txt")) {
|
||||
System.out.println(f.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user