Retrieving Computer Name

Thread Solved

Join Date: May 2008
Posts: 128
Reputation: PhiberOptik is an unknown quantity at this point 
Solved Threads: 4
PhiberOptik's Avatar
PhiberOptik PhiberOptik is offline Offline
Junior Poster

Retrieving Computer Name

 
0
  #1
Dec 29th, 2008
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.
History will be kind to me for I intend to write it.
---------------------------------- Sir Winston Churchill
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 128
Reputation: PhiberOptik is an unknown quantity at this point 
Solved Threads: 4
PhiberOptik's Avatar
PhiberOptik PhiberOptik is offline Offline
Junior Poster

Re: Retrieving Computer Name

 
0
  #2
Dec 29th, 2008
Nevermind Figured it out!

  1. import java.net.*;
  2.  
  3. class myName {
  4.  
  5. public static void main (String args[]) {
  6.  
  7. try {
  8. InetAddress address = InetAddress.getLocalHost();
  9. System.out.println("Hello. My name is " + address.getHostName());
  10. }
  11. catch (UnknownHostException e) {
  12. System.out.println("I'm sorry. I don't know my own name.");
  13. }
  14.  
  15. }
  16.  
  17. }
History will be kind to me for I intend to write it.
---------------------------------- Sir Winston Churchill
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC