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

  • Home
  • SEARCH
  • 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 7803855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:43:13+00:00 2026-06-02T01:43:13+00:00

im studying for my programming final exam. I have to write a program which

  • 0

im studying for my programming final exam. I have to write a program which opens a file which is stored in the string fileName and look in the file for a String called personName and this should print the first string after personName then the program should terminate after printing it,
if the argument personName is not in the file then it should print “this name doen’t exsit” then if an IOException occurs it should then print “there is an IO Error” and the program should exsit using system.exit(0)

the program should use the file info.txt and each line should contain two strings
first string name and second age.

everything must be in one method

data.txt contains

Max 60.0

joe 19.0

ali 20.0

my code for this so far is :

public class Files{

    public void InfoReader(String fileName, String personName)
    {

      try{
         try{
                   // Open the file that is the first 
                  // command line parameter
                  FileInputStream fstream = new FileInputStream("C://rest//data.txt");
                  // Get the object of DataInputStream

                  DataInputStream in = new DataInputStream(fstream);
                  BufferedReader br = new BufferedReader(new InputStreamReader(in));

                  //Read File Line By Line
                  while ((fileName = br.readLine()) != null) {
                      // Print the content on the console
                      (new Files()).infoReader("info.txt","Joe"); //this prints the age
                  }
                  //Close the input stream
                  in.close();
              }

              catch (IOException e)
              {//Catch exception if any
                    System.out.println(" there is an IO Error");
                    System.exit(0);
              }
     }
    catch (Exception e)
              {//Catch exception if any
                    System.out.println("that name doesn't exists");

              }
    }
}

infoReader(info.txt,Joe); should print 19.0

But I am getting a java.lang.StackOverflowError

any help would be much appreciated!!

Thanks in advance!

  • 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-02T01:43:16+00:00Added an answer on June 2, 2026 at 1:43 am

    This is what I think you are trying to do. And if doesn’t, at least can work as an example. Just as amit mentions, your current error is because of the recursive call, which I think is not necessary.

    import java.io.BufferedReader;
    import java.io.DataInputStream;
    import java.io.FileInputStream;
    import java.io.IOException;
    import java.io.InputStreamReader;
    
    public class Files {
    
        public void InfoReader(String fileName, String personName) {
            try {
                // Open the file that is the first command line parameter
                FileInputStream fstream = new FileInputStream(fileName);
    
                // Get the object of DataInputStream
                DataInputStream in = new DataInputStream(fstream);
                BufferedReader br = new BufferedReader(new InputStreamReader(in));
    
                String line = null;
    
                //Loop until there are no more lines in the file
                while((line = br.readLine()) != null) {
                    //Split the line to get 'personaName' and 'age'.
                    String[] lineParts = line.split(" ");
    
                    //Compare this line personName with the one provided
                    if(lineParts[0].equals(personName)) {
                        //Print age
                        System.out.println(lineParts[1]);
                        br.close();
                        System.exit(0);
                    }
                }
    
                br.close();
                //If we got here, it means that personName was not found in the file.
                System.out.println("that name doesn't exists");
            } catch (IOException e) {
                System.out.println(" there is an IO Error");
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm studying iOS programming. i have a program, i will call this program is
I'm studying UNIX programming and was experimenting with read/write system calls. I have a
i'm studying iOS programming. but i have a problem, which is opaque. now assume.
I'm studying for a programming interview in Java which may involve database access. Is
I'm studying programming and as part of my project I have to use the
hello i'm studying iOS programming i created a project, which is an empty application
hi i'm studying iOS programming. i have a trouble to use UITextView. i made
I am studying about system programming system calls. I have a code block in
hi i'm studying a iOS programming, but i have a trouble i want to
I am studying x86 assembly language via the book called Programming from the Ground

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.