Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 11 of 11

Threaded View

  1. #1
    Junior Member
    Join Date
    Sep 2011
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Open a URL and read it line by line (Works in Eclipse but not from Command Line)

    Hi, I am trying to use this code which works fine in Eclipse but when I try to execute the program from the command line it just hangs forever and can never accesses the URL.

    I am trying to run this program from my home computer on a localhost and I have no idea why this isn't working. I read online and some articles suggested using a proxy but I am not behind a proxy or anything. And again this code works fine when I run it in Eclipse so I guess Eclipse is auto-configuring settings to get this code to work.



    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)
    {
    System.out.println("line: " + inputLine);
    site = site + "\n" + inputLine;
    }
    in.close();
    System.out.println("got to this line 3");



    It gets to the print statement inside of the while loop then all of a sudden the connection gets reset and it stops printing the file. It always stops at the same place.
    Last edited by rosco544; September 16th, 2011 at 05:49 PM.


Similar Threads

  1. How to Send command line arguments in Eclipse?
    By JavaPF in forum Java JDK & IDE Tutorials
    Replies: 0
    Last Post: April 23rd, 2009, 11:37 AM
  2. Reading a file line by line using the Scanner class
    By JavaPF in forum File Input/Output Tutorials
    Replies: 0
    Last Post: April 17th, 2009, 07:34 AM
  3. Reading a file line by line using the Scanner class
    By JavaPF in forum Java Code Snippets and Tutorials
    Replies: 0
    Last Post: April 17th, 2009, 07:34 AM
  4. How to Read a file line by line using BufferedReader?
    By JavaPF in forum File Input/Output Tutorials
    Replies: 0
    Last Post: May 19th, 2008, 06:32 AM
  5. How to Read a file line by line using BufferedReader?
    By JavaPF in forum Java Code Snippets and Tutorials
    Replies: 0
    Last Post: May 19th, 2008, 06:32 AM

Tags for this Thread