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 9188857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:06:47+00:00 2026-06-17T20:06:47+00:00

I need to create a program, which does a few things: takes parameters: word

  • 0

I need to create a program, which does a few things:

  • takes parameters: word to find and a path to look
  • looking for the given word at files one by one
  • If the word has found in the file -> print to console filename – file path

Traverse all folders with the same parsing algorithm till it will be possible.

Here is code snipped:

class SearchPhrase {
    // walk to root way
    public void walk(String path, String whatFind) throws IOException {
        File root = new File(path);
        File[] list = root.listFiles();
        for (File titleName : list) {
            if (titleName.isDirectory()) {
                walk(titleName.getAbsolutePath(), whatFind);
            } else {
                if (read(titleName.getName()).contains(whatFind)) {
                    System.out.println("File: " + titleName.getAbsoluteFile());
                }
            }
        }
    }

    // Read file as one line
    public static String read(String fileName) {
        StringBuilder strBuider = new StringBuilder();
        try {
            BufferedReader in = new BufferedReader(new FileReader(new File(fileName).getAbsoluteFile()));
            String strInput;
            while ((strInput = in.readLine()) != null) {
                strBuider.append(strInput);
                strBuider.append("\n");
            }
            in.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return strBuider.toString();
    }

    public static void main(String[] args) {

        SearchPhrase example = new SearchPhrase();
        try {
            example.walk("C:\\Documents and Settings\\User\\Java", "programm");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Program doesn’t compil with following errors:

java.io.FileNotFoundException: C:\Documents and Settings\User\Java Hangman\Java\Anton\org.eclipse.jdt.core.prefs
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at java.io.FileReader.<init>(FileReader.java:72)
at task.SearchPhrase.read(SearchPhrase.java:28)
at task.SearchPhrase.walk(SearchPhrase.java:16)
at task.SearchPhrase.walk(SearchPhrase.java:14)
at task.SearchPhrase.main(SearchPhrase.java:48)

Maybe is is another approach for solving this issue?

  • 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-06-17T20:06:48+00:00Added an answer on June 17, 2026 at 8:06 pm

    you are doing a couple of mistakes here..

    [...]
      if (read(titleName.getName()).contains(whatFind)) {
                    System.out.println("File: " + titleName.getAbsoluteFile());
          }
     [...]
    

    In the above code you are passing the file name to the read method which is wrong. Instead you have to pass the filename along with its path like this…

        if (read(**titleName.getAbsolutePath()**).contains(whatFind)) {
                    System.out.println("File: " + titleName.getAbsoluteFile());
         }
    

    And there is no need of getAbsoluteFile() here

       [...]
    
           BufferedReader in = new BufferedReader(new FileReader(new File(
                    fileName).**getAbsoluteFile()**));
       [...]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need my program to create and edit a config file, which would contain
I am creating a program using wxpython which entails the need to create many
I need a simple C program which creates tcl interpreter, initializes tcl and tk
I need to create program that creates a XML schema like below using System.Xml.XmlSchema
For a school project I need to create a program and it'd be nice
I need to create a simple drawing program in c for graphs, i.e. nodes
I need to create several Raphael objects in my program. field1 and field2 are
I've written a program in Java (executable JAR) and need to create an installer
I want to create a program that produces an executable slideshow. So I need
I want to run my client program 25,000 times. I need to create a

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.