Java URL to InputStream openStream(String urlStr)

Here you can find the source of openStream(String urlStr)

Description

open Stream

License

Open Source License

Declaration

public static InputStream openStream(String urlStr) 

Method Source Code


//package com.java2s;
/*/*from   w ww. jav a  2s.co m*/
 * Xapp (pronounced Zap!), A automatic gui tool for Java.
 * Copyright (C) 2009 David Webber. All Rights Reserved.
 *
 * The contents of this file may be used under the terms of the GNU Lesser
 * General Public License Version 2.1 or later.
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 */

import java.io.*;

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

public class Main {
    public static InputStream openStream(String urlStr) {
        URL url;
        try {
            url = new URL(urlStr);
        } catch (MalformedURLException e) {
            throw new RuntimeException(e);
        }
        InputStream in;
        try {
            in = url.openStream();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return in;
    }
}

Related

  1. getUrlContents(String urlString)
  2. getUrlContents(URL url)
  3. openFileOrURL(String fileNameOrUrl)
  4. openFileOrURL(String name)
  5. openInputStream(URL url)
  6. openStream(URL url)
  7. openStream(URL url)
  8. openStream(URL url)
  9. openStream(URL url)