java 网络编程基础

 InetAddress ip = InetAddress.getByName("www.baidu.com");

        System.out.println("是否可达: "+ip.isReachable(2000));

        System.out.println(ip.getHostAddress());

        InetAddress local = InetAddress.getByAddress(new byte[]{127,0,0,1});

        System.out.println("本机是否可达:" + local.isReachable(5000));

        //获取IP的全限定域名
        System.out.println(local.getCanonicalHostName());

        //当涉及到普通字符串与非西欧字符串的相关转换时,可以用URLEncoder和URLDecoder

        String ChineseUrl = URLEncoder.encode("青岛","GBK");

        System.out.println(ChineseUrl);

        System.out.println(URLDecoder.decode(ChineseUrl,"GBK"));
原文地址:https://www.cnblogs.com/vector11248/p/8297785.html