?? urlconnectiondemo.java
字號:
import java.io.IOException;
import java.io.InputStream;
import java.net.*;
import java.util.Date;
public class URLConnectionDemo
{
public static void main(String[] args)
{
try
{
int n;
//使用指定的URL:"http://www.yahoo.com.cn",來創建URL類對象url
URL url = new URL("http://www.yahoo.com.cn");
URLConnection urlConn = url.openConnection();
InputStream in = urlConn.getInputStream();
System.out.println("Date :"+new Date(urlConn.getDate()));
System.out.println("ContentEncoding :"+urlConn.getContentEncoding());
System.out.println("ContentType :"+urlConn.getContentType());
System.out.println("ContentLength :"+urlConn.getContentLength());
System.out.println("The content of \"http://www.yahoo.com.cn\" is:\n");
while((n = in.read())!=-1)
{
char c = (char)n;
System.out.print(c);
}
}
catch (MalformedURLException e) {e.printStackTrace();}
catch (IOException e) {e.printStackTrace();}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -