• 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();
    }
    }

  • 相关阅读:
    Floyd判圈算法 Floyd Cycle Detection Algorithm
    最优化问题 Optimization Problems & 动态规划 Dynamic Programming
    自平衡二叉搜索树
    树 & 二叉树
    数根
    二叉搜索树BST
    K-Means & Sequential Leader Clustering
    KMP算法
    递归问题的时间复杂度分析
    人工神经网络 Artificial Neural Network
  • 原文地址:https://www.cnblogs.com/xint/p/9013747.html
Copyright © 2020-2023  润新知