java网络通信基础入门教程
文件Sample9_2.java
package chapter09.sample9_2;
import java.io.*;
import java.net.*;
public class Sample9_2 {
public static void main(String[] args) {
try {
// 获取表示名称为wyf的主机对应IP地址的InetAddress对象
InetAddress ip = InetAddress.getByName("silence");
// 打印InetAddress对象描述的IP地址
System.out
.print("InetAddress对应的IP地址为:" + ip.getHostAddress() + ",");
// 打印InetAddress对象描述的主机名
System.out.println("主机名为:" + ip.getHostName() + "。");
} catch (Exception e) {
e.printStackTrace();
}
}
}