从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

posted @ 2019-04-02 14:56  土木转行的人才  阅读(2120)  评论(0编辑  收藏  举报