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

  • Home
  • SEARCH
  • 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 4081534
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:04:24+00:00 2026-05-20T18:04:24+00:00

I grab a line from a text file from a url as a string,

  • 0

I grab a line from a text file from a url as a string, and the string returns the correct value. However, if i call the string after the read the string returns null.

I have no idea what’s going on and would appreciate any guidance.

    static protected String readURL() {
    String u = "http://adamblanchard.co.uk/push.txt";
    URL url;
    InputStream is;
    InputStreamReader isr;
    BufferedReader r;


    try {
      System.out.println("Reading URL: " + u);
      url = new URL(u);
      is = url.openStream();
      isr = new InputStreamReader(is);
      r = new BufferedReader(isr);
      do {
        str = r.readLine();
        if (str != null)
          System.out.println(str);  //returns correct string
      } while (str != null);
    } catch (MalformedURLException e) {
      System.out.println("Invalid URL");
    } catch (IOException e) {
      System.out.println("Can not connect");
    }
    System.out.println(str);  //str returns "null"
    return str;
  }
  • 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-20T18:04:25+00:00Added an answer on May 20, 2026 at 6:04 pm

    The BufferedReader.readLine() method returns null when it reaches the end of file.

    Your program appears to be reading and printing each line in the file, and finally printing the value of str at the bottom. Given that the condition for terminating the read loop is that str is null, that (rather unsurprisingly) is what is printed, and what is returned by the method.

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

Sidebar

Related Questions

I am parsing an input text file. If I grab the input one line
I'm trying to grab thousands of invoices (and other stuff) from a text file
I have a very large text file and I need to gather data from
To grab the inode of a file in PHP, you can use this: $fs
I want to grab the value of a hidden input field in HTML. <input
I need to grab the folder name of a currently executing batch file. I
I'm trying to grab data from a MySQL database. Approach 2 - apply/map style
Using php coding, I'm attempting to make a script which will grab content from
Wondering if anyone knows a nice way to execute a Java command-line program from
I am trying to grab the capital letters of a couple of words and

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.