package com.tz.util.screen;
import java.net.URL;
public class URLDemo {
public static void main(String[] args) throws Exception {
URL url=new URL("hskd");
url.getProtocol();//协议
url.getHost();//主机名
url.getPort();//端口号
url.getPath();//路径
url.getFile();//文件名
url.getQuery();//查询部
int port=url.getPort();
}
}
package com.tz.util.screen;
import java.io.InputStream;
import java.net.URL;
public class URLConnection {
public static void main(String[] args) throws Exception {
URL url=new URL("hskd");
java.net.URLConnection cn=url.openConnection();
InputStream in=cn.getInputStream();
byte[] buf=new byte[1024];
int len=in.read(buf);
new String(buf,0,len);
}
}