参考文章:
http://blog.csdn.net/xb12369/article/details/40543649/
http://www.runoob.com/java/java-url-processing.html
有时候我们需要从网络或者资源服务器等外部非本地环境下载文件,这就需要我们通过URL来访问地址。
URL(Uniform Resource Locator)中文名为统一资源定位符,有时也被俗称为网页地址。表示为互联网上的资源,如网页或者FTP地址。
java.net.URL提供了丰富的URL构建方式,并可以通过java.net.URL来获取资源。
序号 | 方法描述 |
---|---|
1 | public URL(String protocol, String host, int port, String file) throws MalformedURLException. 通过给定的参数(协议、主机名、端口号、文件名)创建URL。 |
2 | public URL(String protocol, String host, String file) throws MalformedURLException 使用指定的协议、主机名、文件名创建URL,端口使用协议的默认端口。 |
3 | public URL(String url) throws MalformedURLException 通过给定的URL字符串创建URL |
4 | public URL(URL context, String url) throws MalformedURLException 使用基地址和相对URL创建 |
序号 |
---|