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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:27:49+00:00 2026-06-13T09:27:49+00:00

I am reading from a BufferedReader , which is wrapping an InputStreamReader . The

  • 0

I am reading from a BufferedReader, which is wrapping an InputStreamReader. The stream comes from a URL with myURL.openStream();

I am trying to read a portion of the stream (characters between startPos and endPos) into a String and then store it in a text file.

    char[] buffer = new char[endPos-startPos];
    reader.skip(startPos);
    int i = 0;
    while(i < (endPos-startPos)){
        buffer[i] = (char) reader.read();
        i++;
    }

The above code works, but seems pretty slow.
I am trying to use the read(char[], int, int) method instead – I assume the Java people have implemented it quicker!

However – it gets about halfway through adding the desired characters into the string then finishes, leaving me with a half full char array.

According to Javadoc it only does this when it either reaches EOF, or “The ready method of the underlying stream returns false, indicating that further input requests would block”. Can anyone tell me what this means? And why is it happening if reading the characters one by one works fine? (Can’t be EOF!)

  • 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-13T09:27:50+00:00Added an answer on June 13, 2026 at 9:27 am

    It’s slow because the data is arriving slowly. Nothing you can do about that in the receiving code. read(char[] ...) returns prematurely because only that many bytes arrived after the first read blocked. If you want to read a specific number of characters you have to loop, either calling read() or read(char[], ...). As BufferedReader is, err, buffered, it won’t make any difference which one you call.

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

Sidebar

Related Questions

While reading from serial port I am using serialport.read(xyz,0,4) where xyz is a byte
I'm reading from a binary data file which is written by invoking the following
I'm reading from the standard input using the read() system call but there's a
I'm reading from a byte stream that contains a series of variable length descriptors
I have this code, which contains a BufferedReader and reads the HTML data from
I am trying to access data from a raw data stream. Before accessing the
I'm trying to read something from within HTML tags and I'm completely stupid when
I'm reading numbers from a txt file using BufferedReader for analysis. The way I'm
I have the following example of reading from a buffered reader: while ((inputLine =
While reading from a configuration file in Perl there might be cases when 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.