import java.net.*;public class Test
{
public static void main(String[] arg)
{
try {
InetAddress ia=InetAddress.getLocalHost();
System.out.println(ia.getHostName());
System.out.println(ia.getHostAddress());
}catch(UnknownHostException e)
{
//error
}
}
}
{
public static void main(String[] arg)
{
try {
InetAddress ia=InetAddress.getLocalHost();
System.out.println(ia.getHostName());
System.out.println(ia.getHostAddress());
}catch(UnknownHostException e)
{
//error
}
}
}
public class netDemo{
public static void main(String args[]){
InetAddress ia=null;
try{
ia=InetAddress.getLocalHost();
System.out.println(ia.getHostName());
System.out.println(ia.getHostAddress());
}catch(UnknownHostException e){
}
}
}
{
public static void main(String args[])
{
System.out.println("looking up localhost");
try
{
InetAddress localAddress = InetAddress.getLocalHost();
System.out.println("the local address is:"+localAddress.());
}
catch(UnknownHostException uhe)
{
System.out.println("Error!");
}
}
} 经过测试成功的!