Java URLConnection Create openURL(String url)

Here you can find the source of openURL(String url)

Description

This is for opening URLs only provided by the programmer.

License

Open Source License

Declaration

public static InputStream openURL(String url) 

Method Source Code


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

import java.io.InputStream;

import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
import java.net.MalformedURLException;

public class Main {
    /** This is for opening URLs only provided by the programmer.
     * URLs provided by the user should be checked for errors and the
     * user notified. Only use this if you have a single response to
     * any non-content situation on opening a URL
     *//*from w w w .  ja  v a 2 s. c  o  m*/
    public static InputStream openURL(String url) {
        URL urlObject;
        InputStream res = null;
        try {
            urlObject = new URL(url);
            URLConnection conn = urlObject.openConnection();
            res = conn.getInputStream();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return res;
    }
}

Related

  1. openConnection(URL url)
  2. openConnection(URL url)
  3. openConnectionForceNoProxy(URL url)
  4. openConnectionTo(URL descriptor)
  5. openInputStream(URL url)
  6. openURLStream(final URI uri)