Thread subject: Explore Your Brain :: Error Getting HostName

Posted by bristimjet on 25-11-2013 12:38
#1

I want to print the local host name, but it always prints null .. how can I get host name ?
Java Code
String hostname = System.getenv("HOSTNAME");
System.err.println("Hostname = " + hostname);
______________________________
Online fax

Edited by bristimjet on 01-12-2013 11:27

Posted by EVA-00 on 26-11-2013 10:20
#2

Try this,

package testing;
import java.net.*;
public class Test
{
public static void main(String[] args) throws UnknownHostException
{
System.out.println(InetAddress.getLocalHost().getHostName());
}