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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:43:35+00:00 2026-05-25T21:43:35+00:00

I am using bufferedReader to read System.in from the user, The user will enter

  • 0

I am using bufferedReader to read System.in from the user, The user will enter a domain address and source address separated by a space.

eg 
auckland.ac.nz. 198.19.20.44
www.esc.auckland.ac. 173.27.28.93
stat.auckland.ac.nz. 52.159.152.105
student.auckland.ac.nz. 64.247.240.232

Now the problem is that once the user finishes entering the data, the input stream does not terminate and hence the program does not get executed. I have written some code for the BufferedReader if anyone is willing to check it and tell me where I went wrong I would greatly appreciate it. Notice the two variables “count” and “n”, is there anyway I can use those to help with that?

     try {
        String fqdn, src, key, temp;
        Integer count;
        int n = 0;

        while ((temp = br.readLine()) != null){
            int divide = temp.indexOf(" ");
            fqdn = temp.substring(0, divide); // divide the input 
            src = temp.substring(divide+1);
            key = fqdn + " " + src;
            //System.out.printf("%d: %s\n", n, key);
            dht.lookup(key);
            n += 1;
        } 
        br.close();
    } catch (NoSuchElementException e) {
        //System.out.printf("end-of-file\n");    
    }
  • 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-25T21:43:36+00:00Added an answer on May 25, 2026 at 9:43 pm

    The loop will terminate when readLine() returns null. The only way that this will happen is if standard input it closed. The user can do this by typing Ctrl+D, but that’s perhaps too much to ask from a typical user. One easy alternative is to ask them to type “done” when they’re done; then your loop should check for that value, rather than null.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to read lines from a BufferedReader in java by using a while
I'm trying to read input from the terminal. For this, I'm using a BufferedReader.
I'm trying to read a text file (Using BufferedReader and FileReader) from my file
I need to get a series of integers from the user. The user will
I'm using read line to get some text from wikipedia. But read line only
I have such code to read a text file using BufferedReader : BufferedReader reader=null;
I am trying to read data from the given web page using Java. public
I'm attempting to write a method that will read a properties file using Class.getResource(),
I'm reading a file using bufferedreader, so lets say i have line = br.readLine();
I'm reading a local file using a BufferedReader wrapped around a FileReader: BufferedReader reader

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.