Java URL Load saveImage(String imageUrl, String destinationFile)

Here you can find the source of saveImage(String imageUrl, String destinationFile)

Description

save Image

License

Open Source License

Declaration

public static void saveImage(String imageUrl, String destinationFile) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;

public class Main {
    public static void saveImage(String imageUrl, String destinationFile) throws IOException {
        URL url = new URL(imageUrl);
        InputStream is = url.openStream();
        OutputStream os = new FileOutputStream(destinationFile);
        byte[] b = new byte[2048];
        int length;
        while ((length = is.read(b)) != -1) {
            os.write(b, 0, length);/*from w  w w  . j  av a 2  s .  c o  m*/
        }
        is.close();
        os.close();
    }
}

Related

  1. readURLThrowException(final String url)
  2. readURLToByteArray(URL url)
  3. readURLToString(URL u, String encoding)
  4. saveFile(final URL url, final File file)
  5. saveFileFromURL(URL url, File destinationFile)
  6. saveImageAsFile(String imageUrl, String destinationFile, boolean overwrite)
  7. saveUrl(String filename, String urlString)
  8. saveUrl(String filename, URL url)
  9. saveURL(URL url, OutputStream os)