标签:字符串 res unknown amp ip地址 class 表示 .net java.net
如果一个类没有构造方法:
A:成员全部是静态的(Math,Arrays,Collections)
B:单例设计模式(Runtime)
C:类中有静态方法返回该类的对象(InetAddress)
public static InetAddress getByName(String host);//根据计算机名或者IP地址的字符串表示得到IP地址对象
import java.net.InetAddress;
import java.net.UnknownHostException;
/*
如果一个类没有构造方法:
A:成员全部是静态的(Math,Arrays,Collections)
B:单例设计模式(Runtime)
C:类中有静态方法返回该类的对象(InetAddress)
public static InetAddress getByName(String host);//根据计算机名或者IP地址的字符串表示得到IP地址对象
*/
public class Example6_3 {
public static void main(String args[]) throws UnknownHostException {
InetAddress address1 = InetAddress.getByName("QY-DENGGL18.gd.ctc.com");// 根据计算机名或者IP地址的字符串表示得到IP地址对象
String name1 = address1.getHostName();// 获取计算机名
String ip1 = address1.getHostAddress();// 获取IP地址
System.out.println(name1 + "--------" + ip1);
InetAddress address2 = InetAddress.getByName("10.18.46.40");// 根据计算机名或者IP地址的字符串表示得到IP地址对象
String name2 = address2.getHostName();// 获取计算机名
String ip2 = address2.getHostAddress();// 获取IP地址
System.out.println(name2 + "--------" + ip2);
}
}
标签:字符串 res unknown amp ip地址 class 表示 .net java.net
原文地址:http://www.cnblogs.com/denggelin/p/6353715.html