Java URL Load saveUrl(String filename, String urlString)

Here you can find the source of saveUrl(String filename, String urlString)

Description

save Url

License

Open Source License

Declaration

public static void saveUrl(String filename, String urlString) throws MalformedURLException, IOException 

Method Source Code


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

import java.io.BufferedInputStream;

import java.io.FileOutputStream;

import java.io.IOException;

import java.net.MalformedURLException;
import java.net.URL;

public class Main {
    public static void saveUrl(String filename, String urlString) throws MalformedURLException, IOException {
        BufferedInputStream in = null;
        FileOutputStream fout = null;
        try {/* w w w . j  a v  a2 s  .c  o m*/
            in = new BufferedInputStream(new URL(urlString).openStream());
            fout = new FileOutputStream(filename);
            byte data[] = new byte[1024];
            int count;
            while ((count = in.read(data, 0, 1024)) != -1)
                fout.write(data, 0, count);

        } finally {
            if (in != null)
                in.close();
            if (fout != null)
                fout.close();
        }
    }
}

Related

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