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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:44:07+00:00 2026-06-15T10:44:07+00:00

When obtaining the information of server return, LOGCAT display 1 2 3. Result is

  • 0

When obtaining the information of server return, LOGCAT display 1 2 3. Result is 1, 5, 6.

When judge if statement, it has the error. I think the result is 1, but it still wrong.

try {
    URL url=new URL(urlstr);
    URLConnection conn = null;
    Log.i("Text", "1");
    try {
        conn = url.openConnection();
        Log.i("Text", "2");
        InputStream in=conn.getInputStream();
        Log.i("Text", "3");
        byte[] buffer=new byte[in.available()];
        in.read(buffer);
        String result=new String(buffer);
        Log.i("Text", "result="+result);
        if(result.equals("1"))
        {    
            Log.i("Text", "4");
        } else {
            Log.i("Text", "5");
        }
        Log.i("Text", "6");
    }
}                                   

I don’t know why. Could anyone help me? Thanks very much.

  • 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-15T10:44:07+00:00Added an answer on June 15, 2026 at 10:44 am

    It’s unclear exactly what you’re trying to achieve, but these three lines have three problems:

    byte[] buffer=new byte[in.available()];
    in.read(buffer);
    String result=new String(buffer);
    
    1. You should almost never use available(). Instead, create a fixed size buffer (it sounds like you’re not expecting much data, so just a small buffer would be fine.) What if there’s no data available when you call available()? You’ll be creating an empty array – surely you don’t want to do that.
    2. You’re ignoring the return value of InputStream.read(). Never do that. You have no idea how much data has actually been read.
    3. You’re creating a String from a byte[] without specifying the encoding. Don’t do that. Which encoding is the data actually using?

    My guess is that you’re either passing an empty array in, or you’re actually reading more than one byte.

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

Sidebar

Related Questions

I would like to know what the simplest/best way for obtaining information about the
I need to access files on the system, namely for obtaining information. File build.prop
I am basically obtaining a decently sized result set (a few thousand) through datanucleus
Is there any possibility in obtaining information about the hand which holds the kinect
Are there any tips, tricks or methods for obtaining profiling/logging/debug information on the runtime
I am using Put (>>) to store information that I am obtaining in Mathematica
I want to receive some information per request, so I think instead of having
Killing the processs while obtaining this information would be fine.
HI am interested in obtaining getting the Enviroment.UserName in a Wpf Browser application. But
My main goal: Collect specific information through the linux server on a windows machine.

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.