how to take computer name in linux
I had tried this code in Windows Xp, it's Ok. but while i run in linux i got error
"Cannot get computer name java.net.UnknownHostException: comcentos: comcentos"
i'm using Centos 5.
i have edit in file etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=yes
HOSTNAME=comcentos
package myPackage;
import java.io.* ;
import java.net.* ;
public class ComputerName {
public static void main ( String[] args ) {
//To get the computer name
try {
String computerName = InetAddress.getLocalHost( ).getHostName ();
System.out.println ( "Computer Name: " + computerName ) ;
}
catch ( Exception e ) {
System.out.println ( " Cannot get computer name " + e ) ;
}
}
}
thanks all for your help