// This is a program focuses on the class URL, and its methods....
//pay attention to the usages of stream, especially the class BufferedReader, a kind of buffer technology.
import java.net.*;
import java.net.URL;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
public class ReadHTML
{
public static void main(String args[])
{
try
{
URL url=new URL("http://localhost/east2"); //注意类URL的用法,这是最简单的用法
System.out.println(url.getHost());
System.out.println(url.getRef());
String strReadLine;
InputStream is=url.openStream(); //利用URL.openStream()方法来获得HTML内容
InputStreamReader isr=new InputStreamReader(is);
BufferedReader br=new BufferedReader(isr);
while ((strReadLine=br.readLine())!=null)
{
System.out.println(strReadLine);
}
br.close();
}
catch (Exception e)
{}
}
}