从主机获取计算机名称
import java.io.UnsupportedEncodingException;/**来 自 N o w J a v a . c o m**/ import java.net.InetAddress; import java.net.UnknownHostException; import java.util.ArrayList; public class Main{ public static void main(String[] argv) throws Exception{ System.out.println(getComputerName()); } public static final String IPADDRESS = "0.0.0.0"; public static String getComputerName() { String hostname = null; try { hostname = InetAddress.getLocalHost().getHostName(); } catch (java.net.UnknownHostException uhe) { /* from 时 代 J a v a - nowjava.com */ } return hostname; } public static String getHostName() { String hostname = null; try { hostname = InetAddress.getLocalHost().getHostName(); } catch (java.net.UnknownHostException uhe) { } //hostname = "testmachine"; return hostname + "[@" + AddressUtil.getIPAddress() + "]"; } public static String getIPAddress() { String ip = IPADDRESS; try { String ha = InetAddress.