运行以下代码,我得到了SocketException
:
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Collections;
import java.util.Enumeration;
public class interfaces {
public static void main(String[] args) throws SocketException {
Enumeration<NetworkInterface> inters = NetworkInterface.getNetworkInterfaces();
for (NetworkInterface iface : Collections.list(inters)) {
System.out.println(iface.getDisplayName());
}
}
}
我正在使用带有 JDK 1.7.0_09-b05 的 OS X 10.8.2。
它在使用 THIS JDK VERSION 的 Windows 上运行良好,在使用 JDK 1.6 的 OS X 上也运行良好。任何人都可以帮我测试一下并检查它是否是JDK的错误吗?
这是堆栈跟踪:
Exception in thread "main"
java.net.SocketException: Can't assign requested address
at java.net.NetworkInterface.getAll(Native Method)
at java.net.NetworkInterface.getNetworkInterfaces(NetworkInterface.java:334)