提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
本地规范主机名
/* from N o w J a v a . c o m*/ //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(localFqdn()); } public static String localFqdn() { try { return InetAddress.getLocalHost().getCanonicalHostName();/*来自 时 代 J a v a 公 众 号*/ } catch (UnknownHostException e) { return null; } } }