java
import java.net.URL;
public class GetDomainFromURL {
public static String getDomainName(String urlString) {
String domainName = "";
try {
URL url = new URL(urlString);
domainName = url.getHost();
} catch (Exception e) {
e.printStackTrace();
}
return domainName;
}
public static void main(String[] args) {
String urlString = "e.com/path/to/page";
String domain = getDomainName(urlString);
System.out.println("Domain name: " + domain);
}
}
顶一下
(0)
0%
踩一下
(0)
0%
- 相关评论
- 我要评论
-