如何从一个URL创建一个开放的? [英] How to create a Uri from a URL?

查看:97
本文介绍了如何从一个URL创建一个开放的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用intent.setData(URI)通过从一个URL获得的数据。为了做到这一点,我需要能够从一个URL创建一个URI(或一个byte []我从URL中读取,或 ByteArrayInputStream的我从创建在字节[] 等)。不过,我想不通这是怎么应该做。

I would like to use intent.setData(Uri) to pass data obtained from a URL. In order to do this, I need to be able to create a Uri from a URL (or from a byte[] I read from the Url, or a ByteArrayInputStream I create from the byte[], etc). However, I cannot figure out how this is supposed to be done.

所以,反正是有创建从一个URL获得的数据的开放的我们无需首先将数据写入到本地文件?

So, is there anyway to create a Uri from data obtained from a URL without first writing the data to a local file?

推荐答案

使用<一个href="http://docs.oracle.com/javase/6/docs/api/java/net/URL.html#toURI%28%29"><$c$c>URL.toURI()安卓DOC )方法。

例如:

URL url = new URL("http://www.google.com"); //Some instantiated URL object
URI uri = url.toURI();

确认来处理相关的异常,如<一个href="http://docs.oracle.com/javase/6/docs/api/java/net/URISyntaxException.html"><$c$c>URISyntaxException.

Make sure to handle relevant exception, such as URISyntaxException.

这篇关于如何从一个URL创建一个开放的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆