我试图使用InetAddress返回用户输入的网站名称的IP地址,但我在语句中收到错误:InetAddress ip = new InetAddress.getByName(site); 显示的错误是:
InetAddress.getByName cannot be resolved to a type
Run Code Online (Sandbox Code Playgroud)
我的代码:
import java.util.*;
import java.net.*;
import java.io.*;
import java.net.InetAddress;
public class getIP {
public static void main(String args[])throws UnknownHostException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String site;
System.out.println("Enter the url :");
site = br.readLine();
try
{
InetAddress ip = new InetAddress.getByName(site);
}
catch(UnknownHostException ee)
{
System.out.println("Website not found.");
}
}
}
Run Code Online (Sandbox Code Playgroud)