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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:32:01+00:00 2026-05-31T09:32:01+00:00

In my java program,I use URLConnection to get a url.It works fine under windows,but

  • 0

In my java program,I use URLConnection to get a url.It works fine under windows,but under linux it doesn’t work.And I wanna know why.

codes:

Properties prop = System.getProperties();
prop.setProperty("http.proxyHost", "127.0.0.1");
prop.setProperty("http.proxyPort", "8080");
System.setProperty("sun.net.client.defaultConnectTimeout", "20000");   
System.setProperty("sun.net.client.defaultReadTimeout", "20000");   
URLConnection conn = new URL(url).openConnection();
InputStream is = conn.getInputStream();
byte [] buff = new byte[is.available()];//1024];
int read = is.read(buff);
System.out.println("buff:" + buff.length);
String result = "";
if(read > 0) {
    result = new String(buff, 0, read);
    read = is.read(buff);
    System.out.println("result:" + result);
}

It turns out that byte is empty and read=0.

But under windows it works fine.

I also tried set the User-Agent field,which makes no different.

HttpURLConnection is also tried,same problem.

Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 8080));
HttpURLConnection conn = (HttpURLConnection)(new URL(url).openConnection(proxy));

This way is tried ,too.Fail either.

All these ways works fine with windows.

The url can be opened fine with firefox on this pc using the same proxy,btw.

  • 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-31T09:32:03+00:00Added an answer on May 31, 2026 at 9:32 am

    In the javadocs for the available() method, it says:

    Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking by the next invocation of a method for this input stream.

    The key is “without blocking”. The method doesn’t return the number of bytes that is expected to be the content length of the url you are trying to read from. Using a fixed sized buffer should solve your problem instead of InputStream.available() which could return 0.

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

Sidebar

Related Questions

I'm writing (under linux or windows+cygwin) a java program that needs to run a
My Java program is in working order when i use it under Windows(Eclipse and
I want to use the java.util.Preferences API but I don't want my program to
If I use HttpsURLConnection in a Java program and try to open an URL
I want to use sqlldr from a java program, but I dont want to
I want to use a linux command line tool from my Java program. I
I created a hello world java program and use lauch4j to convert executable jar
We've written a Java program which we are looking to use and interact with
I'm running a java program that uses many vectors. I'm afraid my use of
When you run a program through the command line, you can use java -Xms

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.