解析URL

欢马劈雪     最近更新时间:2020-01-02 10:19:05

481
解析URL

import java.net.MalformedURLException;

import java.net.URL;/** 来自 n o w j a   v  a . c o m - 时  代  Java**/


public class Main {

  public static void main(String[] argv) {

    try {

      URL url = new URL("http://hostname:80/index.html#_top_");


      String protocol = url.getProtocol(); // http

      String host = url.getHost(); // hostname

      int port = url.getPort(); // 80

      String file = url.getFile(); // index.html

  
展开阅读全文