14.2.4 InetAddress类
InetAddress类表示了一个IP地址,应用程序可调用该类的getLocalHost()、getByName()或者getAllByName()方法来创建一个新的InetAddress对象。
InetAddress类的常用方法有:
public static String getLocalHost()
返回本地主机名。
public static String getByName(String host)
根据主机名host确定主机的IP地址。
public static String[ ] geallByName()
根据主机名host确定主机的所有IP地址。
public String getHostName()
返回当前IP地址的主机名。
public String getHostAddress()
返回IP地址字符串。
public byte[] getAddress()
返回当前对象的IP地址的字节数组。
public String toString()
转换IP地址为字符串。
InetAddress类在网络编程中非常有用,使用InetAddress类的对象,可以很容易地获得网上的各种资源。