Code example for URI

Methods: getScheme, toURL

0
     *            The URI to attempt to read from 
     * @return An InputStream connection 
     */ 
    public static InputStream getInputStream(URI uri) throws IOException {
        // We favor the FileOutputStream 
        if (uri.getScheme().equals(PROTOCOL_FILE)) {
            return new FileInputStream(uri.getPath());
        } 
        return uri.toURL().openStream();
    } 
 
    /** 
     * Attempt to obtain an OutputStream from a URI. The simple case will open 
     * it if it is local. Otherwise, it will call 
     * uri.toURL().openConnection().getOutputStream(), however in some JVMs (MS 
     * at least this fails where new FileOutputStream(url) works. 
     *  
     * @param uri 
     *            The URI to attempt to write to 
     * @return An OutputStream connection 
     */