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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:41:07+00:00 2026-05-23T18:41:07+00:00

I have an InputStreamReader (which is combined with a BufferedReader ). I want to

  • 0

I have an InputStreamReader (which is combined with a BufferedReader).

I want to read the content of the Stream in a loop

while((line = MyStream.readLine()) != null) {
    s.o.p(line);
    String lastline; 
}

but this creates a loop without an end, so my whole program waits for the loop to end .. and waits … and waits.

At the moment, I’ve got a method where you can say how many lines should be read. This works fine, but is very inflexible.

My method at the moment

public void getStatus(int times) throws IOException {
    for (int i = 0; i < times; i++) {
        System.out.println(fromServer.readLine());
    }

I want this method to read all lines and save the last one in a string without the “times” parameter.

  • 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-23T18:41:08+00:00Added an answer on May 23, 2026 at 6:41 pm

    The code you’ve got will work if it reaches the end of a stream.

    My guess is that this is a network stream, and the other end isn’t closing the connection. That won’t end up with you going into the loop ad infinitum though – it’ll end up with you just hanging on the readLine call, waiting for either the other end to close the stream, or for more data to arrive.

    You need to either have some way of detecting you’re finished (e.g. a terminating line / the connection closing) or know how many lines to read ahead of time.

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

Sidebar

Related Questions

I have to read a dict.txt file which contains one string for line and
I have utf-8 file which I want to read and display in my java
I have this code, which contains a BufferedReader and reads the HTML data from
I have a String Array which is contain dates that read from a CSV
I have this code in Java: InputStreamReader isr = new InputStreamReader(getInputStream()); BufferedReader ir =
I have a BufferedReader (generated by new BufferedReader(new InputStreamReader(process.getInputStream())) ). I'm quite new to
I have Java console app, which i want to control from another computer. I
I have a bufferedreader and for some reason it wont read the text from
i have a EditText in android in which i want the user to enter
I have an activity which I want to show ListView with list of topics,

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.