Results 1 to 10 of 10
  1. #1
    Nubkadiya is offline Member
    Join Date
    May 2010
    Posts
    9
    Rep Power
    0

    Default how to download a image from a webserver to java application

    i want to download a image from a webserver to my java application. this image contains the map. i want to use it for my application. can you please provide me with a code example.

    please.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    One way is to read the bytes of the image file into an array and use ImageIO.read() to convert them to an image:
    Java Code:
            ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
            try {
              image = javax.imageio.ImageIO.read(bais);
            }catch(IOException x) {x.printStackTrace();}

  3. #3
    Nubkadiya is offline Member
    Join Date
    May 2010
    Posts
    9
    Rep Power
    0

    Default

    can you please provide me with the whole code. please

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,433
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Nubkadiya View Post
    can you please provide me with the whole code. please
    Read the API documentation for the ImageIO utility class; it even has a method to read an entire image given a URL.

    kind regards,

    Jos

  5. #5
    Nubkadiya is offline Member
    Join Date
    May 2010
    Posts
    9
    Rep Power
    0

    Default

    i have read the whole API doc. and the image is showing perfectly. now i want to get that image to my java application.

    i have tried a code

    and i dont know why this line shows a error

    URL url = new URL(http://maps.google.com/maps/api/stat...sensor=false);


    can someone help me.

  6. #6
    Nubkadiya is offline Member
    Join Date
    May 2010
    Posts
    9
    Rep Power
    0

    Default

    i tried putting " " in the begining and ending in the URL also. but still the error same..

  7. #7
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,433
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Nubkadiya View Post
    i have read the whole API doc. and the image is showing perfectly. now i want to get that image to my java application.

    i have tried a code

    and i dont know why this line shows a error

    URL url = new URL(http://maps.google.com/maps/api/stat...sensor=false);


    can someone help me.
    I clicked on that link and my browser told me that I had to login first. That is an entirely different problem, but it has nothing to do with downloading images.

    kind regards,

    Jos

  8. #8
    Nubkadiya is offline Member
    Join Date
    May 2010
    Posts
    9
    Rep Power
    0

    Default

    no no. i just want to know how to put the URL in there

    when i put like that netbean giving me a error.

    tried with " " also.

  9. #9
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,433
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Nubkadiya View Post
    no no. i just want to know how to put the URL in there

    when i put like that netbean giving me a error.

    tried with " " also.
    Read the API documentation for the URL class: it needs a String representation when you want to construct a URL with one parameter for its constructor.

    kind regards,

    Jos

  10. #10
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    shows a error
    Can you copy and paste the full text of the error message here?

Similar Threads

  1. download file/image?
    By dinosoep in forum New To Java
    Replies: 10
    Last Post: 12-15-2009, 09:45 AM
  2. showing image in web application
    By Juuno in forum Advanced Java
    Replies: 3
    Last Post: 05-11-2009, 04:36 AM
  3. Replies: 1
    Last Post: 10-21-2008, 09:21 AM
  4. image download from server
    By willemjav in forum Java Applets
    Replies: 2
    Last Post: 04-03-2008, 10:13 PM
  5. How to download an image from a HTTP URL
    By Valeriano in forum Networking
    Replies: 1
    Last Post: 05-20-2007, 08:35 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •