Java示例获取URL的各个部分


Java示例获取URL的各个部分

import java.net.URL;



public class NewClass {

   public static void main(String args[]) throws Exception {

      URL u = new URL("https://www.codingdict.com/javaexamples/net_singleuser.htm");

      System.out.println("The URL is " + u);

      System.out.println("The file part is " + u.getFile());

      System.out.println("host is " + u.getHost());

      System.out.println("path is " + u.getPath());

      System.out.println("port is " + u.getPort());

      System.out.println("default port is " + u.getDefaultPort());

   }

}