Hi ,
Given this :
URL u=new URL("someURL");
How do i identify the top level domain of the URL..
Hi ,
Given this :
URL u=new URL("someURL");
How do i identify the top level domain of the URL..
Use URL#getHost()
and if necessary thereafter a String#split()
on "\\."
.
Update: if you actually have an IP address as host, then you need to make use of InetAddress#getHostName()
independently.
The host part of the url conforms to RFC 2732 according to the docs. It would imply that simply splitting the string you get from
String host = u.getHost();
would not be enough. You will need to ensure that you conform to the RFC 2732 when searching the host OR if you can guarantee that all addresses are of the form server.com then you can search for the last . in the string and grab the tld.