从url中获得域名
import java.net.MalformedURLException; import java.net.URL; /** * * @author csh * */ public class AAAA { public static void main(String[] args) { String str = "http://new.dongying.gov.cn/art/2018/8/31/art_43576_3069835.html"; URL url=null; try { url = new URL(str); String host = url.getHost(); System.out.println(host); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
结果显示:
new.dongying.gov.cn
本文来自博客园,作者:土木转行的人才,转载请注明原文链接