954,518 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

how to take computer name in linux

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

onsir
Light Poster
38 posts since Apr 2007
Reputation Points: 10
Solved Threads: 1
 

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

mrynit
Newbie Poster
15 posts since Jan 2008
Reputation Points: 10
Solved Threads: 0
 

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

onsir
Light Poster
38 posts since Apr 2007
Reputation Points: 10
Solved Threads: 1
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You