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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:13:21+00:00 2026-06-08T15:13:21+00:00

I have a question for you all. I am going for speed, and I

  • 0

I have a question for you all. I am going for speed, and I need to use this method a lot, so the more efficient this method is, the better.

My code:

private void method(final String name) {
    final URL url = new URL("http://www.somewebsite.com/blah.php?name=" + name);
    final BufferedReader in = new BufferedReader(new InputStreamReader(url.openConnection().getInputStream()));
    final String totalText = in.readLine();
    in.close();
    //other stuff using the totalText variable
}

This method works, but I am asking if there is a more efficient way for this to work.

Important Notes Concerning the code I am reading:

  • The entire source code from the website is only one line long.
  • There are no HTML tags with the website code. It is all raw text.
  • 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-08T15:13:23+00:00Added an answer on June 8, 2026 at 3:13 pm

    1. If its one line of code, as you have changed you question then do the following…
    Use Only InputStream and Scanner.

    final URL url = new URL("http://www.somewebsite.com/blah.php?name=" + name);
    InputStream i = url.openStream();
    Scanner scan = new Scanner(i);
    final String totalText = scan.nextLine();
    

    2. If mulitple lines then, I will advice you not to create a String object every time, cause creating Object on the Heap is expensive.

    These 2 below lines will create a lot of String object on the heap.

    ((inputLine = in.readLine()) != null)

    totalText += inputLine;

    Use StringBuilder which is Mutable, and at the end assign it to the String reference using toString() method.

    Eg:

    StringBuilder totalText;
       String ftotal;
    
       while ((inputLine = in.readLine()) != null) {
        totalText.append(inputLine);
    }
    
    
       ftotal = totalText.toString();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

ASP.Net MVC3 is cool and all but I have this question more out of
Dear all,Now i have this question in my java program,I think it should be
This is more of a challenge question than something I urgently need, so don't
I have question about XSLT1.0. The task is to write out in HTML all
hi all i have a question about hiding records in crystal report and i
I just have a question thats been pozzling my head all morning. I want
Dear all, I have a question about Facebook Page: ( NOT user profile page,
Greetings all, I have a question. On my MOSS 2007 dev box, I created
I have a question concerning Core Data and how, if at all, Entities get
Hey all. I have a question on how to implement the following with Django.

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.