获取主机名的IP地址
import java.net.InetAddress; import java.net.UnknownHostException; public class Main { /*来自 时 代 J a v a - nowjava.com*/ public void m() { try { InetAddress addr = InetAddress.getByName("nowjava.com"); byte[] ipAddr = addr.getAddress(); // Convert to dot representation String ipAddrStr = ""; for (int i = 0; i < ipAddr.length; i++) { if (i > 0) { ipAddrStr += "."; }