import java.io.File;
import java.util.ArrayList;
import java.util.List;
public class FileTraversal {
public static void main(String... _) {
String path = "D:/";
List data = new ArrayList();
data = getData(path, data);
for (int i = 0; i < data.size(); i++) {
System.out.println(data.get(i));
}
}
private static List getData(String path, List data) {
File f = new File(path);
if (f.isDirectory()) {
File[] fs = f.listFiles();
if(null!=fs)
for (int i = 0; i < fs.length; i++) {
data = getData(fs[i].getPath(), data);
}
} else if (f.getName().endsWith(".txt")) {
data.add(f.getName());
}
return data;
}
}