Java examples for Network:URL
Parsing a URL
import java.net.MalformedURLException; import java.net.URL; public class Main { public static void main(String[] argv) { try {/*from ww w.ja v a 2 s . com*/ 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 String ref = url.getRef(); // _top_ } catch (MalformedURLException e) { } } }