![URL类的实例化 [Java],第1张 URL类的实例化 [Java],第1张](/aiimages/URL%E7%B1%BB%E7%9A%84%E5%AE%9E%E4%BE%8B%E5%8C%96+%5BJava%5D.png)
public URL(String spec);
通过一个表示URL地址的字符串可以直接构造一个URL对象eg: URL url = new URL("http;//www.atguigu.com/’);
public URL(URL context , String spec);
通过基URL和相对URL构造一个URL对象eg: new URL(url , “download.html”);
public URL(String protocol , String host , String file);
通过: 协议名,主机名/域名,文件名来构造一个URL对象
一个域名之下可以有多个主机名 eg: new URL(“http” , “www.atguigu.com” , “download.html”);
public URL(String protocol , String host , int port , String file);
通过 : 协议名,主机名/域名,端口号,文件名来构造一个URL对象eg: new URL(“http” , “www.atguigu.com”,8080,“download.html”);
java.net.MalformedURLException继承于java.io.IOException
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)