int filename = 100;
String[] fileName = new String[filename];
int a = 0;
int totalCount = 0;
int wordCount = 0;
// Count the number of documents containing the query
System.out.println("Please enter the query :");
Scanner scan2 = new Scanner(System.in);
String word2 = scan2.nextLine();
String[] array2 = word2.split(" ");
int[] numofDoc = new int[array2.length];
for (int b = 0; b < array2.length; b++) {
numofDoc[b] = 0;
for (int i = 0; i < filename; i++) {
try {
BufferedReader bf = new BufferedReader(new FileReader(
"C:\\Users\\user\\fypworkspace\\FYP\\abc"
+ i + ".txt"));
int matchedWord = 0;
Scanner s2 = new Scanner(bf);
{
while (s2.hasNext()) {
if (s2.next().equals(array2[b]))
matchedWord++;
}
}
if (matchedWord > 0)
numofDoc[b]++;
} catch (IOException e) {
System.out.println();
}
}
_resultArea.append(array2[b]
+ " --> This number of files that contain this term "
+ numofDoc[b]+ newline);
}
嗨,这是我的代码,用于计算包含用户键入的特定输入的文件数。此代码分析文本文件的文件夹并搜索文本文件是否有输入。 我现在面临的问题是,我现在宣布数组大小为100.它意味着它将处理100个文本文件,无论该文件夹是否有100个文件。 如何让程序处理文件夹内的文本文件的确切数量?如何让数组的大小自动增长和缩小?
注意:文本文件的数量是动态的。它没有固定数量的文件夹内的文本文件。