当前位置: 技术问答>java相关
怎么可能老是出错?
来源: 互联网 发布时间:2015-02-16
本文导语: 这是我写一个程序,看看哪里出错了,我总是找不出错误。thxpackage net; import java.net.*; public class IPAddressSeek { public IPAddressSeek() { super(); } public static void main(String[] args) { InetAddress hostAddress; byte[] integer...
这是我写一个程序,看看哪里出错了,我总是找不出错误。thxpackage net;
import java.net.*;
public class IPAddressSeek
{
public IPAddressSeek()
{
super();
}
public static void main(String[] args)
{
InetAddress hostAddress;
byte[] integer_address;
if (args.length==0)
{
try
{
hostAddress=InetAddress.getLocalHost();
integer_address=hostAddress.getAddress();
System.out.println("The domain name of localhost is:nttt"+hostAddress.getHostname());
System.out.println("The IPAddress of localHost in the form of standardDot is:nttt"+hostAddress.getHostAddress());
System.out.println("The IPaddress of localhost in the form of 4_integer_byte is:nttt"+integer_address[0]+"t"+integer_address[1]+"t"+integer_address[2]+"t"+integer_address[3]);
}catch(UnknowHostException e)
{e.printStackTrace();}
}else
{
try
{
hostAddress=InetAddress.getByName(args[0]);
integer_address=hostAddress.getAddress();
System.out.println("The domain name of localhost is:nttt"+hostAddress.getHostname());
System.out.println("The IPAddress of localHost in the form of standardDot is:nttt"+hostAddress.getHostAddress());
System.out.println("The IPaddress of localhost in the form of 4_integer_byte is:nttt"+ integer_address[0]+"t"+integer_address[1]+"t"+ integer_address[2]+"t"+integer_address[3]);
}catch(UnknowHostException e)
{e.printStackTrace();}
}
}
}
import java.net.*;
public class IPAddressSeek
{
public IPAddressSeek()
{
super();
}
public static void main(String[] args)
{
InetAddress hostAddress;
byte[] integer_address;
if (args.length==0)
{
try
{
hostAddress=InetAddress.getLocalHost();
integer_address=hostAddress.getAddress();
System.out.println("The domain name of localhost is:nttt"+hostAddress.getHostname());
System.out.println("The IPAddress of localHost in the form of standardDot is:nttt"+hostAddress.getHostAddress());
System.out.println("The IPaddress of localhost in the form of 4_integer_byte is:nttt"+integer_address[0]+"t"+integer_address[1]+"t"+integer_address[2]+"t"+integer_address[3]);
}catch(UnknowHostException e)
{e.printStackTrace();}
}else
{
try
{
hostAddress=InetAddress.getByName(args[0]);
integer_address=hostAddress.getAddress();
System.out.println("The domain name of localhost is:nttt"+hostAddress.getHostname());
System.out.println("The IPAddress of localHost in the form of standardDot is:nttt"+hostAddress.getHostAddress());
System.out.println("The IPaddress of localhost in the form of 4_integer_byte is:nttt"+ integer_address[0]+"t"+integer_address[1]+"t"+ integer_address[2]+"t"+integer_address[3]);
}catch(UnknowHostException e)
{e.printStackTrace();}
}
}
}
|
God, you are lazy,
change "UnknowHostException" to "UnknownHostException"
change "getHostname" to "getHostName"
change "UnknowHostException" to "UnknownHostException"
change "getHostname" to "getHostName"