• Post Reply Bookmark Topic Watch Topic
  • New Topic

when local machine address is not available ?  RSS feed

 
sunil choudhary
Ranch Hand
Posts: 144
Java Redhat Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(This is also for Angela's Confusion )
Why will this not give the name of the local machine.I donot see any typo in this
Is it possible that there might be some other condition when the IP address of a stand alone machine is not available to this program.
the program is catching exception on my machine.
import java.*;
import java.net.*;
class myname
{
public static void main(String args[])
{

try
{
InetAddress m = InetAddress.getLocalHost();
byte[] add =m.getAddress();
for (int i=0;i<add.length;i++)>
{
int unsignedByte=add[i]<0 ? add[i]+256:add[i];
System.out.print(unsignedByte+".");
}
}
catch(Exception e)
{
System.out.println("Sorry I do not know my name "+e);
}
}
}
 
Ramesh Ch
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in your code for loop is wrong
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!