Java URL Download fetchURL(String url_string)

Here you can find the source of fetchURL(String url_string)

Description

Fetch the contents of a URL

License

Open Source License

Declaration

private static byte[] fetchURL(String url_string) 

Method Source Code

//package com.java2s;
// set the license text bitstream

import java.net.URL;
import java.net.URLConnection;

public class Main {
    /**//from  ww  w . j a  v  a2 s.c  o m
     * Fetch the contents of a URL
     */
    private static byte[] fetchURL(String url_string) {
        try {
            URL url = new URL(url_string);
            URLConnection connection = url.openConnection();
            byte[] bytes = new byte[connection.getContentLength()];

            // loop and read the data until it's done
            int offset = 0;

            while (true) {
                int len = connection.getInputStream().read(bytes, offset,
                        bytes.length - offset);

                if (len == -1) {
                    break;
                }

                offset += len;
            }

            return bytes;
        } catch (Exception exc) {
            return null;
        }
    }
}

Related

  1. downlod(String url, File dest)
  2. downNetImg(String filePath, String remotePath, String htmlUrl, String fileName)
  3. downPicture(String filePath, String imageUrl, String fileName)
  4. fetchUrl(String _url, String charset)
  5. fetchURL(String url)
  6. fetchURL(String urlStr, List errors, Map requestProperties)
  7. fetchUrl(URL url)
  8. fetchUrl(URL url)
  9. fetchURL(URL url)