RSS Forums RSS

Retrieving Computer Name

Please support our Java advertiser: Programming Forums
Thread Solved
Reply
Posts: 124
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

  #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
AddThis Social Bookmark Button
Reply With Quote  
Posts: 124
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

  #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  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Views: 431 | Replies: 1 | Currently Viewing: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 2:56 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC