A quick example of how to get the name of the localhost using the Java InetAddress class. String hostname = null; try { InetAddress localhost = Address.getLocalHost(); if (localhost != null) { hostname = localhost.getHostName(); } } catch (UnknownHostException e) { e.printStackTrace(); } System.out.println(“Hostname is ” + (hostname != null ? hostname : “Unknown”) );

Paul Osborne – Java/PHP Developer
Freelance and contract Java and PHP programming and development services.
-
Latest
-
Categories
-
Archives