?? url3.java
字號:
import java.net.*;
import java.io.*;
import java.util.Date;
public class URL3
{
public static void main(String args[])
{
String urlname = "http://www.edu.cn/index.html";
if (args.length>0)
urlname = args[0];
new URL3().display(urlname);
}
public void display(String urlname)
{
try
{
URL url = new URL(urlname);
URLConnection uc = url.openConnection();
System.out.println("當(dāng)前日期: "+new Date(uc.getDate())+
"\r\n"+"文件類型: "+uc.getContentType()+"\r\n"+
"修改日期: "+new Date(uc.getLastModified()));
int c, len;
len = uc.getContentLength(); //獲取文件長度
System.out.println("文件長度: "+len);
if(len>0)
{
System.out.println("文件內(nèi)容:");
InputStream in = uc.getInputStream(); //建立數(shù)據(jù)輸入流
int i = len;
while(((c=in.read())!=-1) && (i>0))
{ //按字節(jié)讀取所有內(nèi)容
System.out.print((char)c);
i--;
}
}
}
catch(MalformedURLException me)
{
System.out.println(me);
}
catch(IOException ioe)
{
System.out.println(ioe);
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -