编写一个输出本地IP的方法,源码入下:
import java.net.*;public class TestIP
{
public static void main(String args[])
{
InetAddress ia = null;
String s = null;
try
{
s = ia.getHostAddress();
}
catch(Exception e)
{
}
System.out.println(s);
}
}可输出结果是null.为什么?
import java.net.*;public class TestIP
{
public static void main(String args[])
{
InetAddress ia = null;
String s = null;
try
{
s = ia.getHostAddress();
}
catch(Exception e)
{
}
System.out.println(s);
}
}可输出结果是null.为什么?
解决方案 »
- java国际化的问题
- 为什么会没输出呢?有关JAVA的正则表达式问题
- 网页信息抽取
- 搞了一个小时,还是不能返回值。高手指点一下啊。
- 在jsp中ResultSet中连续输出多少条系统会出报错误
- 求一本地applet可以与application通信的例程
- 关于微软虚拟机不支持GBK编码问题
- 关于文件操作!急!
- 看来这个论坛也是徒有虚名,我的JB7编译成可执行文件的问题到现在没人能解决,难道这就是专家的水平?
- jdk1.2.2 for sco download?
- 这两个有啥区别?是不是后一个可以支持中文??
- 请问Class.getDeclaredMethod(String name, Class... parameterTypes)中 Class... parameterTypes怎么理解
String s = null; try {
s = ia.getHostAddress();
} catch (Exception e) { }
System.out.println(s);
import java.net.UnknownHostException;public class CSDN5
{
public static void main(String args[])
{
InetAddress ia = null;
try {
ia=InetAddress.getLocalHost();
} catch (UnknownHostException e1) {
e1.printStackTrace();
}
String s = null;try
{
s = ia.getHostAddress();
}
catch(Exception e)
{}
System.out.println(s);
}
}