I currently have a Java program that loops through several hundred files in a directory on my windows machine searching for a string in each file.
I do this my creating an array out of the 200+ file names and the program executes without issue.
I wanted to know if its possible to either
A. Use a wild card so every time I change the files I am searching through I dont have to list the 200+ files as an array in my code.
or
B Just searching all of the files inside a specific folder.
Below is my code where inputFile is the array of files.
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();