Results 1 to 3 of 3
  1. #1
    happyday is offline Member
    Join Date
    Nov 2008
    Posts
    3
    Rep Power
    0

    Default how can i save an image from url

    Hi everyone ,
    Maybe this is a simple question for someone but i would like to know how can i save an image from a http url and save it in a jpg file somehwere in the disk, in fact will save it in database.
    Can anyone tell me any example ?
    Thanks in advance !

  2. #2
    neilcoffey is offline Senior Member
    Join Date
    Nov 2008
    Posts
    286
    Rep Power
    6

    Default

    Essentially, you:
    - construct a URL with your URL
    - call openConnection(), then call getInputStream() on the resulting URLConnection object
    - pull out the data from the input stream as with any old input stream, probably wrapping a BufferedInputStream around it

    A while ago I put up on my web site an example of reading data from a URL in Java, which covers this case of binary data, plus the case of reading character data.

  3. #3
    poroto20 is offline Member
    Join Date
    Jan 2009
    Posts
    34
    Rep Power
    0

    Default

    You can do it only with 1 line:

    Java Code:
    FileUtils.copyURLToFile(new URL(....), new File(....));
    You have to include commons-io.jar from Apache

Similar Threads

  1. how to save image as jpg?
    By katie in forum New To Java
    Replies: 4
    Last Post: 04-15-2010, 10:07 AM
  2. how to save image to disk after using pixelgrabber
    By shishirg in forum Advanced Java
    Replies: 5
    Last Post: 02-28-2009, 02:45 PM
  3. Save a jpg image on server
    By yadavjpr in forum Java Servlet
    Replies: 1
    Last Post: 11-21-2008, 01:49 PM

Posting Permissions

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