提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
从Inet4Address获取Ip地址
/*from 时代Java - nowjava.com*/ //package com.nowjava; import java.net.Inet4Address; import java.net.UnknownHostException; public class Main { public static void main(String[] argv) throws Exception { System.out.println(getIpAddress()); } public static String getIpAddress() throws UnknownHostException { return Inet4Address.getLocalHost().getHostAddress(); }/* 来自 nowjava - 时 代 Java*/ }