How do I Get a localhost Hostname?

Bookmark this example!  
Category: java.net, viewed: 1670 time(s).
 
import java.net.InetAddress;
import java.net.UnknownHostException;
 
public class HostnameExample
{
    public static void main(String[] args)
    {
        try
        {
            InetAddress address = InetAddress.getLocalHost();
			
            System.out.println("Hostname: " + address.getHostName());
        } catch (UnknownHostException e)
        {
            e.printStackTrace();
        }
    }
}
 
 
Can't find what you are looking for? Join our FORUMS and ask some questions!
Firefox 2
Google

100 Top & Latest

GetJava Download Button

Locations of visitors to this page
eXTReMe Tracker
visitor stats