package urlConn;import java.io.*;
import java.net.*;
import java.util.Date;class URLDemo
{
  public static void main(String args[]) throws Exception
  {
    URL url=new URL("http://www.sina.com.cn");
    HttpURLConnection open=(HttpURLConnection)url.openConnection();
    open.connect();
    BufferedReader buf=new BufferedReader(new InputStreamReader(open.getInputStream()));
    String temp=null;
    while((temp=buf.readLine())!=null)System.out.println(temp);
    buf.close();  }
}

解决方案 »

  1.   

    把网页保存成文件<%@ page import="java.text.*"%>
    <%@ page import="java.util.*"%>
    <%@ page import="java.io.*"%>
    <%@ page import="java.net.*"%>
    <%
     URL stdURL = null;
     BufferedReader stdIn = null;
     PrintWriter stdOut = null;
     try {
      stdURL = new URL("http://www.163.com");
     }
     catch (MalformedURLException e) {
       throw e;
     }try {
       stdIn = new BufferedReader(new InputStreamReader(stdURL.openStream()));
       stdOut = new PrintWriter(new BufferedWriter(new FileWriter("c:/163.html")));
     }
     catch (IOException e) {
     } /***把URL指定的页面以流的形式读出,写成指定的文件***/
     try {
       String strHtml = "";
       while((strHtml = stdIn.readLine())!=null) {
       stdOut.println(strHtml);
       }
     }
     catch (IOException e) {
       throw e;
     }
     finally {
       try {
         if(stdIn != null)
           stdIn.close();
         if(stdOut != null)
           stdOut.close();
       }
       catch (Exception e) {
         System.out.println(e);
       }
     }
    %>