提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
获取本地主机IP
/** nowjava - 时代Java 提 供 **/ //package com.nowjava; import java.net.InetAddress; import java.net.UnknownHostException; public class Main { public static void main(String[] argv) throws Exception { System.out.println(getLocalHostIP()); } public static String getLocalHostIP() { try { InetAddress addr = InetAddress.getLocalHost(); return addr.getHostAddress(); } catch (UnknownHostException e) {