File folder2 = new File("C:\\Users\\user\\fypworkspace\\TextRenderer");
File[] listOfFiles2 = folder.listFiles();
System.out.println("Please enter the required word :");
Scanner scan2 = new Scanner(System.in);
String word2 = scan.nextLine();
String [] array2 = word2.split(" ");
{
for (int i=0; i < listOfFiles.length; i++)
{
if ((listOfFiles2[i].getName().endsWith(".txt")))
{
try
{
BufferedReader in= new BufferedReader(new FileReader(listOfFiles2[i].getName()));
int numDoc = 0;
Scanner s2 = new Scanner(listOfFiles2[i].getName());
{
while (s2.hasNext())
{
if (s2.next().equals(word2)) numDoc++;
}
System.out.println("The number of document containing the term is " + numDoc);
}
in.close();
} catch (IOException e) {
}
这是我的代码,用于计算包含特定术语的文档数。 每次程序在文档中找到特定术语时,它都会增加numDoc计数器。 但是,此代码不执行任何操作。我做错了什么?
答案 0 :(得分:1)