【发布时间】:2014-10-26 18:14:22
【问题描述】:
我目前有一个 Java 程序,它在我的 windows 机器上的一个目录中循环数百个文件,在每个文件中搜索一个字符串。
我这样做是从 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();
【问题讨论】:
标签: java filesystems