网络编程-demo

2017-09-14  本文已影响0人  Eve0

public class NetConnectionTest {

    public static void main(String[] args) throws Exception {
        URL url = new URL("http://www.baidu.com");
        BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
        String res = "";
        
        while(null!=(res = reader.readLine())){
            System.out.println(res);
        }
        reader.close();

    }

}
public class NetConnectionTest {

    public static void main(String[] args) throws Exception {
        InetAddress ia = InetAddress.getLocalHost();//访问本机
        System.out.println(ia);
        InetAddress baidu = InetAddress.getByName("www.baidu.com");//通过域名访问
        System.out.println(baidu);
    }

}
上一篇 下一篇

猜你喜欢

热点阅读