j_inetaddress.java
来自「Java网络编程应用:包括简易聊天程序的客服端和服务器端的源代码」· Java 代码 · 共 23 行
JAVA
23 行
import java.net.InetAddress;
import java.net.UnknownHostException;
public class J_InetAddress
{
public static void main(String[] args){
String s="www.buaa.edu.cn";
InetAddress ts=null;
try{
ts=InetAddress.getByName(s);
}
catch(UnknownHostException e){
System.err.println(e);
}
if(ts!=null){
System.out.println("The IP address of beihang is :"+ts.getHostAddress());
System.out.println("The host name of beihang is :"+ts.getHostName());
}
else{
System.out.println("can not access "+s);
}
}
};
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?