62.txt
来自「是一个 java 基础学习软件 有设计说明」· 文本 代码 · 共 63 行
TXT
63 行
//
URL
URL(Uniform Resource Locator)----统一资源定位器,表示Internet上某一资源的地址。
URL组成: 协议名和资源名
protocol:resourceName
URL举例:
http://www.sun.com/
http://home.netscape.com/home/welcome.html
http://www.sun.com.cn/developers/
//
java.net.URL类
常用构造方法
public URL(String spec);
URL u1 = new URL(“http://home.netscape.com/home/”);
public URL(URL context, String spec);
URL u2 = new URL(u1, “welcome.html”);
public URL(String protocol, String host, String file);
URL u3 = new URL(“http”, “www.sun.com”, “developers/index.html” );
public URL (String protocol, String host, int port, String file);
URL u4 = new URL(“http”, “www.sun.com”, 80, “developers/index.html” );
//
URL类应用举例
import java.io.*;
import java.net.*;
public class URLReader{
public static void main(String args[]){
try{
URL tirc = new URL("http://www.tsinghua.edu.cn/");
BufferedReader in = new BufferedReader(new
InputStreamReader(tirc.openStream()));
String s;
while((s = in.readLine())!=null)
System.out.println(s);
in.close();
}catch(MalformedURLException e) {
System.out.println(e);
}catch(IOException e){
System.out.println(e);
}
}
}
//
URL类应用举例
程序URLReader.java输出结果:
<html>
<head>
<title>清华大学网站首页</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta http-equiv="refresh" content="0;URL=./eng/index.htm">
</head>
<body bgcolor="#FEFAF2" text="#000000" topmargin=0 leftmargin=0 marginwidth=0 marginheight=0>
</body>
</html>
//如使用了代理服务器,则使用下述命令运行:
//java -Dhttp.proxyHost=<hostname|hostIP> -Dhttp.proxyPort=<port> URLReader
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?