How do I save images downloaded from the Internet?

I have the URL to an image stored on the Internet. Is it possible to open a connection and store the image on my computer? I'm not totally new to this, I've written a small program that could read text files from an ftp server, but it's my first try at downloadning images. Here's the code I'm using
String wwwfile = ....;
               System.out.println(protocol+host+wwwfile);
                    URL url = new URL(protocol+host+wwwfile);
                    URLConnection urlc = url.openConnection();
                    InputStreamReader reader = new InputStreamReader(urlc.getInputStream());
                    File file = new File(path,fileName);
                    OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(file));
                    int c;
                    while((c = reader.read())!=-1)
                    writer.write(c);
                    reader.close();
                    writer.flush();
                    writer.close();
When I read text files, I used BufferedReader/PrintWriter instead of InputStreamReader/OutputStreamReader. The picture I want to download seems to be downloaded, it's stored on the computer, but upon viewing the picture, the browser displays the icon telling me the picture is abscent.
What is it that I'm doing wrong?
regards
simon

Ah, this might be the problem. You're using an InputStreamReader and OutputStreamWriter to wrap the streams with reader/writers. This is bad. This will corrupt binary data.
Try this:
        System.out.println(protocol + host + wwwfile);
        URL url = new URL(protocol + host + wwwfile);
        URLConnection urlc = url.openConnection();
        // Use InputStream/OutputStreams instead of Reader/Writers for binary data.
        // Otherwise it will get corrupted.
        InputStream in = urlc.getInputStream();
        File file = new File(path, fileName);
        OutputStream out = new BufferedOutputStream(new FileOutputStream(file));
        int c;
        while ((c = in.read()) != -1) {
            out.write(c);
        in.close();
        // You don't have to flush the file if you're
        // closing it right after.
        out.close();

Similar Messages

  • How do i save a photo from the internet to my photo library?

    I want to save some copyright-free photos and clip art to my photo library. How do I do that?

    Mirella M wrote:
    How do I save photos from the internet? Right clicking did not list "save as" as one of the options.
    Most times you can simply drag the photo onto the desktop and it creates a file which you can then move elsewhere.
    Some websites don't allow their photo's to be used.
    However OS X has a neat trick, simply hold
    command shift 4
    and a cross hairs appears which you then can take a snapshot of anything on the screen just about, even upload it here with the camera icon.
    there is also command shift 3 which takes the whole screen.
    there are a bunch of others, like to take a picture of the current window etc.
    Finally Quicktime allows video recording of the whole screen, for recording segments you may need something like SnapZPro X still.

  • How do I save a photo from the internet to my computer? Right clicking is giving "save photo" as one of my options

    How do I save photos from the internet? Right clicking did not list "save as" as one of the options.

    Mirella M wrote:
    How do I save photos from the internet? Right clicking did not list "save as" as one of the options.
    Most times you can simply drag the photo onto the desktop and it creates a file which you can then move elsewhere.
    Some websites don't allow their photo's to be used.
    However OS X has a neat trick, simply hold
    command shift 4
    and a cross hairs appears which you then can take a snapshot of anything on the screen just about, even upload it here with the camera icon.
    there is also command shift 3 which takes the whole screen.
    there are a bunch of others, like to take a picture of the current window etc.
    Finally Quicktime allows video recording of the whole screen, for recording segments you may need something like SnapZPro X still.

  • How do I open apps downloaded from the internet on my macbook?

    I downloaded an app from the Avery website to create labels. When I download the app and try to open it i get a garbled message. Any idea how I can open the app?

    I was not given an option of which to download. I have this problem all the time and someone told me how to fix it once, but I cannot remember what the answer was.

  • How do I import an image directly from the internet without printing and scanning it in first?

    How do I import an image directly from the internet without printing and scanning it in first?

    You can also Ctrl click on the image, save the image to your desktop and open it in Photoshop.
    1.
    2.
    3. Open in Photoshop by double-clicking on the saved image on your Desktop or Cmd o in Photoshop.
    I don't see any point to copying and pasting from a browser into a new file in Photoshop.
    If you want to put an image onto an already open image in Photoshop, use the File > Place... command and select your saved image.
    Gene

  • My 9.2.3 iphoto is broke. why can't i access the photos i uploaded to it or them images i downloaded from the internet?

    my iphoto 9.22.3 is broke. why can't i access the images i download from the internet or access the pics i took with my camera? thjey are there when i open iphoto, but not there when i try to use them???

    You already said  that
    the answer us again
    And again exactly are you doing? How are you trying to attach them?  The basic answer is to use the media browser in the lower left hand corner of the attach window under Media ==> photos. ==> iPhoto
    LN

  • I recently updated my macbook, i don't know if that has any effect to my recent problem, but when i try to download and save .mp3 files from the internet, like i have done in the past, it downloads but not as an mp3 file, its "blank"

    i recently updated my macbook, i don't know if that has any effect to my recent problem, but when i try to download and save .mp3 files from the internet, like i have done in the past, it downloads but not as an mp3 file, its "blank" and when i try to open it, i can't? I NEED HELP !

    Here is the download page

  • I have just upgraded to OSX 10.6.8 and now I cannot open or save PDF files from the internet. I get a dialogue box saying the QuickTime plugin has failed. I have tried to download the latest plugin but this doesn't work. Can anyone help?

    I have just upgraded to OSX 10.6.8 and now I cannot open or save PDF files from the internet using either Safari or Firefox. I get a dialogue box saying the QuickTime plugin has failed. Can anyone help?

    Is this what you downloaded: iTunes 10.7?
    When the update fails what if any error report do you get, specifically? Please do this before trying again:
    Repair the Hard Drive and Permissions
    Boot from your Snow Leopard Installer disc. After the installer loads select your language and click on the Continue button. When the menu bar appears select Disk Utility from the Utilities menu. After DU loads select your hard drive entry (mfgr.'s ID and drive size) from the the left side list.  In the DU status area you will see an entry for the S.M.A.R.T. status of the hard drive.  If it does not say "Verified" then the hard drive is failing or failed. (SMART status is not reported on external Firewire or USB drives.) If the drive is "Verified" then select your OS X volume from the list on the left (sub-entry below the drive entry,) click on the First Aid tab, then click on the Repair Disk button. If DU reports any errors that have been fixed, then re-run Repair Disk until no errors are reported. If no errors are reported click on the Repair Permissions button. Wait until the operation completes, then quit DU and return to the installer.
    If DU reports errors it cannot fix, then you will need Disk Warrior and/or Tech Tool Pro to repair the drive. If you don't have either of them or if neither of them can fix the drive, then you will need to reformat the drive and reinstall OS X.

  • How to I add Camera Raw presets I've downloaded from the internet?

    How to I add Camera Raw presets I've downloaded from the internet? I have a mac and I use Creative Cloud.

    Presets are stored under Library>Application Support>Adobe>Camera Raw>Settings. Install them there. Once done, load the settings:
    Benjamin

  • How do I stop click-thru "'Firefox' is an application downloaded from the Internet. Are you sure you want to open it?"?

    Every single time I launch Firefox 20 under Mac OS X 10.7.5 I get the click-thru warning message "'Firefox' is an application downloaded from the Internet. Are you sure you want to open it?". How do I stop this? There are internet postings and previous postings about solving this using Terminal commands for OS X 10.5.x & 10.6.x, but these commands do NOT work in 10.7.x or 10.8.x. This seems to be a Firefox ONLY issue, and solving it by globally turning off OS X security features as recommended before in a previously closed thread seems like a really BAD solution. Is there a "Firefox only" solution, or will I just have to stop using Firefox?

    I had upgraded to Firefox 20 using the automatic update process, so the last time I'd downloaded a .dmg and manually installed Firefox was a long time ago. I trashed Firefox 20, downloaded a new .dmg and manually transferred to Applications folder and this persistent message ended. I assume if I'd ever launched from the open .dmg the same error message would result, so the fix offered was a solution even though the cause was something different since I only used the automatic update process and never manually handled Firefox .dmg downloads.

  • Everytime i open a safe website I get this message ""ai-13.php" is a script application downloaded from the Internet. Are you sure you want to open it?" How do I get this to stop?

    Question
    Everytime I open a safe website I get this message "“ai-13.php” is a script application downloaded from the Internet. Are you sure you want to open it?" How do I get this to stop?

    WZZZ,
    Thanks, the following command (ran as root) worked for me!
    xattr -d com.apple.quarantine /Applications/Google\ Chrome.app
    Chrome is set to start on launch, so I'd get the following warning on every start/restart
    Google Chrome” is an application downloaded from the Internet. Are you sure you want to open it?

  • How do I disable this - "Firefox.app" is an application downloaded from the Internet. Are you sure you want to open it?

    how do I disable this - “Firefox.app” is an application downloaded from the Internet. Are you sure you want to open it?

    If you want to open it confirm that you do. You will not be asked that question again after the first time you open it
    Unless you are keeping Firefox in the .dmg it was downloaded in.  That is to say, if you obtained Firefox in a .dmg, and you have kept the .dmg mounted, and are launching Firefox from the mounted .dmg, then you will ALWAYS get that warning.   You should copy Firefox from the mounted .dmg to your Applications Folder (or anywhere you prefer), and then eject the mounted .dmg.  Unless you need to install Firefox on another system, you can then delete the .dmg.

  • Disabling that"..is an application which was downloaded from the Internet."

    Downloaded Camino and use it. Now I do not want that warning anymore on every start. I do not give **** how Apple rates security of the file. I know the application is safe so I want to click some checkbox to disable warning on Camino start:
    '“Camino” is an application which was downloaded from the Internet. Are you sure you want to open it?'
    The only unsafe Camino is to Safari as recent version of Safari is really troubled with hick-ups and freezes while Camino seems to be very similar except that it does not have those issues Safari has.
    I can only say what guy named Yeroen (read it if want):
    http://forums.macrumors.com/showthread.php?p=4414559
    It is really Microsoft way. Can Apple get rid of that troll recenly hired in the company that makes Mac OS X now look like piece of... art that behaves so obnoxiously to a user? I cannot guess where Apple got those new ideas, but they definitelly look like some transplant from Vista and XP obnoxiousness. The only what comes to my mind is some folks that were contracted or hired from Microsoft. Shortsighted with narrow vision and lack of basic education on ergonomics of any user interface.
    Hey Apple I dropped Windows because of that! Why do you do this to me now?
    Sincerely,
    Maciek Samsel

    Okay. It looks like when copying from mounted .dmg file to Applications folder one needs to start Camino on that account and say once to allow start. This has to be done on account that was used to copy the file from downloaded .dmg.
    In my scenario, I have administrative account which is separate from users (and of course my own as I am not administrator daily). So Camino was bothering me until I went to administator account and started Camino once. Apparently it had to make some writings into hidden system files to rememeber the choice and the choice was made across accounts.
    I remember that similar issues were in Final Cut Express: you had to start the application from administrative account (the one that you used to install the application) once and after that you could easily go and use the application on other accounts at any time.
    Looks like this is some sort of pattern which I considered ill as user really should not need to do that pointless start on account that is not supposed to be used for the application. Installation account and use account should be interpretted as two separate with no overlap of preferences. Now this issue was in FCE,but as far as Camino... it sounds like Apple extends this lame pattern to security control and internal system preferences.
    Sincerely,
    Maciek Samsel

  • "........" is an application which was downloaded from the Internet. Are you sure you want to open it?

    I get the following warning every time I try to open a recently download application. I'm running Mavericks 10.9.3
    "xxxxx' is an application which was downloaded from the Internet. Are you sure you want to open it?
    How do I disable this warning for a particular application?
    Update: problem solved. The Mac in question has multiple users, but only one user has administrator privileges. The problem was simply that the application in question had never been opened by the administrator. Once the administrator opened the application the warning went away.

    If using a mouse, you can right click on the application installer this will give you an "Open with" popup and you can chooes to open the application installer using the standard installer.
    Another method to do the same exact thing is to hold the Control key while left clicking on the Application installer will give you the exact same popup menu.

  • Can I download from the internet the software required to enable my A1197 wireless mouse?

    Can I download from the internet th esoftware to enanble my wireless mouse, model A1197?

    You already said  that
    the answer us again
    And again exactly are you doing? How are you trying to attach them?  The basic answer is to use the media browser in the lower left hand corner of the attach window under Media ==> photos. ==> iPhoto
    LN

Maybe you are looking for

  • Production Orders cost

    Hi gurus, I'm not sure if this is the right forum, but I'm PP consultant and just starting a new projec on which the most important topics are production and costs so here are my questions. 1.- What is the responsability of the PP consultant regardin

  • Word doc from javaScript

    I am creating the MS word document in java script by using command document.execCommand('SaveAs', true, 'test.doc'); now my requirement is Each page in above generated word document should have a footer with a centered �Page x of y� line. please tell

  • How to create a database using Java?

    Hi there.. I'm a student who is currently studying IT and was asked to do a project based on database but create using Java.. since i'm a beginner..i was wondering whether is it possible to do that? and if it is possible.. can you kindly show me a sa

  • Read characteristics value of AUSP-ATWRT

    Hi, There is a code in AUSP-ATWRT and i want to get the text of this code like : AUSP-ATINN = ZHC_REFUSREASON and AUSP-ATWRT = 01-22.04.2009-A07.001 I want to get the mean of the bold area, A07. How to do that? Thanks

  • Debugging WLS 4.5.1 with Symantech VCafe

    Hi, If anybody knows how to debug EJBs running in WLS remotely from Visual Cafe 3.0, will you please describe how you do it? Config: WLS 4.5.1, Cafe 3.0, Oracle 8i, NT 4.0 & Solaris Thanks!!!! [eytan.vcf]