Here you can find the source of getInputStream(URL url)
Parameter | Description |
---|---|
url | the url to open as a stream |
Parameter | Description |
---|---|
IOException | if there is trouble creating the stream |
public static InputStream getInputStream(URL url) throws IOException
//package com.java2s; /**// w w w . jav a 2 s . c o m * Copyright 2001 Sun Microsystems, Inc. * * See the file "license.terms" for information on usage and * redistribution of this file, and for a DISCLAIMER OF ALL * WARRANTIES. */ import java.net.URL; import java.io.FileInputStream; import java.io.InputStream; import java.io.IOException; public class Main { /** Returns an input stream for the given URL. If the URL is pointing to a local file, returns a file input stream * suitable for MemoryMapped IO, otherwise, returns a buffered input stream. * @param url the url to open as a stream * @return the stream associated with the URL * @throws IOException if there is trouble creating the stream */ public static InputStream getInputStream(URL url) throws IOException { if (url.getProtocol().equals("file")) { return new FileInputStream(url.getFile()); } else { return url.openStream(); } } }