创建URL

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

451
创建一个URL

import java.net.MalformedURLException;/*时 代 J     a    v  a - nowjava.com*/

import java.net.URL;


public class Main {

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

    try {

      // With components.

      URL url = new URL("http", "hostname", 80, "index.html");


      // With a single string.

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

    } catch (MalformedURLException e) {

    }

  }

}