How to get Host name in Java

Views: 128 Ask New Question


Hot to get the System name/ Host name/ Machine name in Java?

On By

1 Answer


String hostName = "UNKNOWN";
try {
    hostName = InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException e) {
    System.out.println("Unable to resolve host");
}
System.out.println("HostName is:" + hostName);
On By


Answer This Question