Finding your hostname from Java

6 AM July 6, 2005

How to find a hostname for your local machine, from DevX:


    private String findHostName() {

        try {

            return InetAddress.getLocalHost().getHostName();

        } catch (UnknownHostException e) {

            return "unknown";

        }

    }

By alang | # | Comments (4)
(Posted to javablogs and Java)
© 2003-2006 Alan Green