怎么从一个网上下载网页阿,还要保存或者显示出来,下面是我一部分,需要再外什么才能完成,高手指教补充程序:
// $Id: HelloClient.java,v 1.1 2004/09/14 03:45:23 mzwang Exp mzwang $
import java.io.*;
import java.net.*;public class HelloClient{
public static void main(String args[]){
String host = "www.ee.polyu.edu.hk";
int port = 27000;

host = args[0];
port =  Integer.parseInt(args[1]);
  try{
Socket s = new Socket(host,port);

InputStream instream = s.getInputStream();
InputStreamReader reader = new InputStreamReader( instream);
BufferedReader bufferedreader = new BufferedReader( reader );

String msg = bufferedreader.readLine();
System.out.println("message from the server: "+msg);

s.close();

}
catch (Exception e){
System.out.println("error: "+e);
}

}
}还有一个是:我要发信息给echo port(port7)然后还要发挥给echo  it means: send message to the echo port and read back the echoed message下面是一部分code需要修改:import java.io.*;
import java.net.*;
public class echo3{
    public static void main(String args[]) {
// declaration section:
// declare a server socket and a client socket for the server
// declare an input and an output stream
        ServerSocket echoServer = null;
        String line;
        DataInputStream is;
        PrintStream os;
        Socket clientSocket = null;
// Try to open a server socket on port7
        try {
           echoServer = new ServerSocket(7);
        }
        catch (IOException e) {
           System.out.println(e);
        }   
// Create a socket object from the ServerSocket to input the message
// Open input and output streams
    try {
           clientSocket = echoServer.accept();
           is = new DataInputStream(clientSocket.getInputStream());
           os = new PrintStream(clientSocket.getOutputStream());
// Once we receive data, echo that data back to the client.
           while (true) {
             line = is.readLine();
             os.println(line); 
           }
        }   
    catch (IOException e) {
           System.out.println(e);
        }
    }
}急救马上回复阿 我等

解决方案 »

  1.   


    import java.io.BufferedReader;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.net.URL;
    import java.net.URLConnection;public class GetSource {
    public static void main(String args[]) throws Exception {
    String host = "http://www.163.com"; URLConnection url = new URL(host).openConnection(); try { InputStream instream = url.getInputStream();
    InputStreamReader reader = new InputStreamReader(instream);
    BufferedReader bufferedreader = new BufferedReader(reader); String msg = bufferedreader.readLine();
    while(msg!=null) {
    System.out.println("message from the server: " + msg);
    msg = bufferedreader.readLine();
    }
    } catch (Exception e) {
    System.out.println("error: " + e);
    } }
    }第一个帮你改了
      

  2.   

    还有一个是:我要发信息给echo port(port7)然后还要发挥给echo  it means: send message to the echo port and read back the echoed message下面是一部分code需要修改:import java.io.*;
    import java.net.*;
    public class echo3{
        public static void main(String args[]) {
    // declaration section:
    // declare a server socket and a client socket for the server
    // declare an input and an output stream
            ServerSocket echoServer = null;
            String line;
            DataInputStream is;
            PrintStream os;
            Socket clientSocket = null;
    // Try to open a server socket on port7
            try {
               echoServer = new ServerSocket(7);
            }
            catch (IOException e) {
               System.out.println(e);
            }   
    // Create a socket object from the ServerSocket to input the message
    // Open input and output streams
        try {
               clientSocket = echoServer.accept();
               is = new DataInputStream(clientSocket.getInputStream());
               os = new PrintStream(clientSocket.getOutputStream());
    // Once we receive data, echo that data back to the client.
               while (true) {
                 line = is.readLine();
                 os.println(line); 
               }
            }   
        catch (IOException e) {
               System.out.println(e);
            }
        }
    }急救马上回复阿 我等
      

  3.   

    http://dev.csdn.net/develop/article/65/65663.shtm这个例子可以调试成功自己 试试
      

  4.   

    这个IP 应该怎么用啊 楼上?
    我用自己的IP 但是被拒绝
      

  5.   

    我是要communicate with the (TCP) echo port (port 7)