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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:00:33+00:00 2026-05-25T15:00:33+00:00

I am trying to read a URL into a String and it starts reading

  • 0

I am trying to read a URL into a String and it starts reading in the URL and then just stops at the same line every time and hangs. This happens with any URL and it happens when I run the program from the command line on Windows 7. When I run the same program in Eclipse it never hangs and reads in the entire website.

It always gets to “got to line 2” and inside of the while loop but never to “line 3”.

Here is the code I am using below. Is there some type of a size limit or something when doing it right through Windows on the command line?

URL link = new URL("http://www.yahoo.com");
System.out.println("got to this line 1");
BufferedReader in = new BufferedReader(new InputStreamReader(link.openStream()));

System.out.println("got to this line 2");
        //InputStream in = link.openStream();
        String inputLine = "";
        int count = 0;
        while ((inputLine = in.readLine()) != null)
        {
            site = site + "\n" + inputLine;
            System.out.println(inputLine);
        }
        System.out.println("exited the while loop.");
        in.close();
        System.out.println("got to this line 3");
  • 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-25T15:00:33+00:00Added an answer on May 25, 2026 at 3:00 pm

    I took that code, put it in a main method, added a site variable as String site = "";, compiled it with IntelliJ, and ran it from a Windows 7 command prompt, and it worked fine:

    > java -version
    java version "1.6.0_26"
    Java(TM) SE Runtime Environment (build 1.6.0_26-b03)
    Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02, mixed mode)
    

    Output of the program:

    got to this line 1
    got to this line 2
    <all of the page source>
    exited the while loop.
    got to this line 3
    

    Does it work the same if you comment out the line that prints out each line as its read in?

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

Sidebar

Related Questions

I am trying to read a string into an array and I get the
I'm trying to read in an image URL. As mentioned in the java documentation,
I'm trying to read a .doc file into a database so that I can
I have this code where I am trying to read an image from Url:
I'm trying to read an image from the net using ImageIO: URL url =
I am trying to load a JSON string into an EXTJS grid. The error
I am trying to read a file into NSXMLDocument. Here my code: NSString *urlString
I'm trying to read a feed from Yahoo Pipes into a Silverlight Application. I
I'm trying to read my stock portfolio into a script. The following works with
I'm trying to use URLLIB2 to open a URL and read back the contents

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.