zoukankan      html  css  js  c++  java
  • URL请求响应(Socket)

    package com.socket;

    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.net.InetAddress;
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.net.UnknownHostException;

    public class SocketTest {
    public static void main(String[] args) throws IOException {
    /*System.out.println("本机信息======");
    // 获取本地主机的InetAddress实例
    InetAddress address = InetAddress.getLocalHost();
    // 获取计算机名
    String hostName = address.getHostName();
    // 获取IP地址
    byte[] ip = address.getAddress();
    System.out.println("主机名:" + hostName);
    System.out.print("ip地址:" + ip[0]+ip[1]+ip[2]+ip[3]+" ");
    System.out.println("其他机器信息======");
    InetAddress othersAddress = InetAddress.getByName("www.runoob.com");
    byte[] othersHostName = othersAddress.getAddress();
    System.out.println(othersHostName[1]);*/
    System.out.println("url测试======");
    URL url = new URL("http://www.baidu.com");
    InputStream is = url.openStream();
    InputStreamReader isr = new InputStreamReader(is, "utf-8");
    BufferedReader br = new BufferedReader(isr);
    String data = br.readLine();
    while(data != null) {
    System.out.println(data);
    data = br.readLine();
    }
    br.close();
    isr.close();
    is.close();
    }
    }

  • 相关阅读:
    OAF_OAF控件系列9
    OAF_OAF控件系列8
    OAF_OAF控件系列7
    OAF_OAF控件系列5
    OAF_OAF控件系列4
    OAF_OAF控件系列3
    OAF_OAF控件系列3
    OAF_OAF控件系列2
    OAF_OAF控件系列1
    PLSQL_性能优化索引Index介绍(概念)
  • 原文地址:https://www.cnblogs.com/xint/p/9013747.html
Copyright © 2011-2022 走看看