欢迎使用CSDN-markdown编辑器

来源:互联网 发布:science杂志知乎 编辑:程序博客网 时间:2024/06/05 09:36

网络编程-InetAddress 使用例子

用了这么多年每次用都忘记,感觉不用就废弃了,干脆写下来,想看了回头看看,巩固下基础。

/**
* Description:

* Copyright (C), 2005-2015,David

* Thies program is protected by copyright

* David. Program name

* Date:2015年5月19日

*
* @author

* @version 1.0
*
*/

public class InternetAddressTest {    public static void main(String[] args) {        try {            InetAddress ip = InetAddress.getByName("mv.xxx.com");            System.out.println(ip.getHostAddress());            System.out.println(ip.getHostName());            // 判断是否可以到            System.out.println(ip.isReachable(5000));            System.out.println(ip.getCanonicalHostName());            System.out.println(ip.getLoopbackAddress());            InetAddress local = InetAddress.getByAddress(new byte[] { 127, 0,                    0, 1 });            System.out.println(local.isReachable(5000));            //获得全限定名            System.out.println(local.getCanonicalHostName());        } catch (UnknownHostException e) {            e.printStackTrace();        } catch (IOException e) {            e.printStackTrace();        }    }}

这个类是网络编程的基础

还有两个非常简单和编码相关URLEncoder和URLDecoder

0 0
原创粉丝点击