Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4030296
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:27:12+00:00 2026-05-20T11:27:12+00:00

File folder2 = new File(C:\\Users\\user\\fypworkspace\\TextRenderer); File[] listOfFiles2 = folder.listFiles(); System.out.println(Please enter the required word

  • 0
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) {
    }

This is my code for counting the number of documents that contain a specific term.
Every time the program finds a specific term inside the document, it will increment numDoc counter.
This code does not do anything, however. What am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T11:27:12+00:00Added an answer on May 20, 2026 at 11:27 am
    1. Add System.out.println() throughout your code to output important information for debugging.
    2. Not directly related but you can use a enhance for loop to loop through the files. See: http://download.oracle.com/javase/tutorial/java/nutsandbolts/for.html
    3. Your System.out.println for your total is inside your loop and it should be outside after you have finished looping through all the documents.
    4. (And maybe the most important) You are not handling your IOException. At the least printout a stack trace or the message from the exception.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

//Count the number of documents available File folder = new File(C:\\Users\\user\\fypworkspace\\TextRenderer); File[] listOfFiles =
I have the local file path as c:\new folder\pdf\today\k.pdf I want to replace the
for (a = 0; a < filename; a++) { try { System.out .println( _
Directories some_folder, some_folder_1, some_folder_2, and some_folder_3 don't exist initially. File folder1 = new File(some_folder/some_folder_1);
Am working on file / folder event capturing of OS X 10.5 and 10.6
I'm copying a file from folder A to folder B and then trying to
I would like to move a file or folder from one place to another
Suppose you have a full path to an accessible file or folder on the
Is it possible to use the OpenFileDialog class select a file OR folder? It
In normal WebForms scenario, any root-relative URLs (e.g. ~/folder/file.txt) inside CSS files such as:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.