本文介绍了如何在Java中检查域是否存在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我的电子邮件地址是 [email protected] ,我想检查 yahoo.com 是否是是否有效域。

Suppose my email address is [email protected] and I want to check if yahoo.com is a valid domain or not.

有谁能告诉我我可以使用哪种Java API?

Can anyone tell me which Java API I can use for this?

推荐答案

InetAddress 有方法确定主机的IP地址,鉴于主持人的名字。

InetAddress has getByName() method to determine the IP address of a host, given the host's name.

如果找不到主机的IP地址(如果给定的主机名无效),。

If no IP address for the host could be found ( in case the given host name is not valid) , UnknownHostException will be thrown.

因此,您只需在调用 InetAddress.getByName()时尝试捕获 UnknownHostException 。如果捕获到 UnknownHostException ,则表示您的输入主机名无效。

So , you just try to catch an UnknownHostException when calling InetAddress.getByName() . If UnknownHostException is caught , that means your input host name is invalid.

这篇关于如何在Java中检查域是否存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 06:13