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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:41:17+00:00 2026-06-05T22:41:17+00:00

I’m trying to get an image off the internet from an URL in java.

  • 0

I’m trying to get an image off the internet from an URL in java. I’m using the following code.

URL url = new URL(webAddress);
image = ImageIO.read(url);

Sometimes it works and sometimes it just hangs indefinitely, depending on what WebAddress is. No error message, it just keeps running and doing nothing.

There are definitely images at the addresses where it hangs forever, as confirmed by copying and pasting them into a web browser. There appears to be no pattern to which ones work and which ones don’t- they’re all jpegs. I’ve done some searching and found some other methods for getting an image from an URL, but the same thing happens with all of them- they work on some images and hang on others.

Do you have any idea what could be causing this, and how to fix it?

  • 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-05T22:41:18+00:00Added an answer on June 5, 2026 at 10:41 pm

    Hmm I’m not sure try this and see if any change or error is thrown. I also think maybe you have setRedirects(boolean b) to false this also maybe giving problems but try this first:

        URLConnection con = null;
        InputStream in = null;
        try {
            String webadd="urls go here try the two you have had probelms with and success";
            URL url = new URL(webadd);
    
            con = url.openConnection();
            con.setConnectTimeout(10000);
            con.setReadTimeout(10000);
            in = con.getInputStream();
            Image img = ImageIO.read(in);
            if (img != null) {
                System.out.println("Loaded");
            } else {
                System.out.println("Could not load");
    
            }
        } catch (IOException ex) {
            ex.printStackTrace();
        } finally {
            if(is != null) {
                try {
                     is.close();
                } catch(IOException ex) {
                     // handle close failure
                }
            }
    
            if(con != null) {
                con.disconnect();
            }
        }
    }
    

    EDIT:
    or maybe a bug?: https://bugs.java.com/bugdatabase/view_bug;jsessionid=2bc7386e2f8b4e2550f8b10122f?bug_id=6309072 to check this if the error still occurs with the above code try:

            Image img=new ImageIcon(url).getImage();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have thousands of HTML files to process using Groovy/Java and I need to
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text

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.