Here you can find the source of getLocalAddress(int port)
public static URL getLocalAddress(int port)
//package com.java2s; //License from project: Open Source License import java.net.*; public class Main { public static URL getLocalAddress(int port) { try {//from w ww . j a v a 2 s. c om return new URI("http://localhost:" + port).toURL(); } catch (URISyntaxException | MalformedURLException e) { throw new RuntimeException(e); } } }