我目前有一个Java程序,它循环浏览Windows机器上的目录中的数百个文件,在每个文件中搜索字符串。Wild Card在Java中搜索文件系统文件夹
我这样做是为了从200多个文件名中创建一个数组,并且程序执行没有问题。
我想知道,如果可能要么
A.使用通配符所以每次我改变我寻遍我不要的文件时必须列出了200多个文件,在我的代码的数组。
或
B只搜索特定文件夹内的所有文件。
下面是我的代码,其中inputFile是文件数组。
try {
br = new BufferedReader(new FileReader(inputFile[i]));
try {
while((line = br.readLine()) != null)
{
countLine++;
//System.out.println(line);
String[] words = line.split(" ");
for (String word : words) {
if (word.equals(inputSearch)) {
count++;
countBuffer++;
}
}
if(countBuffer > 0)
{
countBuffer = 0;
lineNumber += countLine + ",";
}
}
br.close();
A. [是](http://stackoverflow.com/questions/1384947/java-find-txt-files-in-specified-folder)。 B. [是](http://stackoverflow.com/questions/794381/how-to-find-files-that-match-a-wildcard-string-in-java)。 – RossC 2014-09-02 13:03:56
也许正在监视文件系统更改效率更高: http://docs.oracle.com/javase/tutorial/essential/io/notification.html – mariusm 2014-09-02 13:07:55