DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Java (http://www.daniweb.com/forums/forum9.html)
-   -   Retrieving Computer Name (http://www.daniweb.com/forums/thread164793.html)

PhiberOptik Dec 29th, 2008 1:21 pm
Retrieving Computer Name
 
hey guys,
I was wondering if there is anyway that my java app could retrieve the computer name.

IE
My computer could be named
"PhiberOptik-desktop"

I want to retreive
"PhiberOptik-desktop"
!

Thanks PO.

PhiberOptik Dec 29th, 2008 1:39 pm
Re: Retrieving Computer Name
 
Nevermind Figured it out!

import java.net.*;

class myName {

public static void main (String args[]) {

try {
InetAddress address = InetAddress.getLocalHost();
System.out.println("Hello. My name is " + address.getHostName());
}
catch (UnknownHostException e) {
System.out.println("I'm sorry. I don't know my own name.");
}

}

}


All times are GMT -4. The time now is 11:34 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC