import java.io.File;
import java.util.ArrayList;
public class FileSearchTest {
static ArrayList<String> fileList = new ArrayList<String>();
public static void main(String[] args) {
String contentString = ".ini";
ArrayList<String> resultArrayList = getallFiles(
"D:/Program Files (x86)", contentString);
for (int i = 0; i < resultArrayList.size(); i++) {
System.out.println(resultArrayList.get(i));
}
System.out.println(resultArrayList.size());
}
public static ArrayList<String> getallFiles(String path, String content) {
File file = new File(path);
File[] files = file.listFiles();
for (int i = 0; i < files.length; i++) {
if (files[i].isDirectory()) {
getallFiles(files[i].getAbsolutePath(),content);
} else {
String strFileName = files[i].getAbsolutePath();
if (strFileName.endsWith(content)) {
fileList.add(strFileName);
}
}
}
return fileList;
}
}
时间: 2024-10-13 01:56:40