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"));

 

posted @ 2018-01-16 17:32  vector11248  阅读(120)  评论(0编辑  收藏  举报