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

it works fine for me using Ubuntu 7.10 and java version 1.5.0_14. check your java config?

What is i must config java. I'm using java jdk_1.6 update 3 with netbeans 6.0
while i intsall java i used jdk-6u3-nb_0-linux.sh
thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.