Skip to content

Instantly share code, notes, and snippets.

@lanetteamkaushal
Created January 19, 2016 09:01
Show Gist options
  • Save lanetteamkaushal/933f045e79fa43ae6c4b to your computer and use it in GitHub Desktop.
Save lanetteamkaushal/933f045e79fa43ae6c4b to your computer and use it in GitHub Desktop.
Common codes
import java.net.*;
import java.io.*;
public class ParseURL {
public static void main(String[] args) throws Exception {
URL aURL = new URL("http://example.com:80/docs/books/tutorial"
+ "/index.html?name=networking#DOWNLOADING");
System.out.println("protocol = " + aURL.getProtocol()); //http
System.out.println("authority = " + aURL.getAuthority()); //example.com:80
System.out.println("host = " + aURL.getHost()); //example.com
System.out.println("port = " + aURL.getPort()); //80
System.out.println("path = " + aURL.getPath()); // /docs/books/tutorial/index.html
System.out.println("query = " + aURL.getQuery()); //name=networking
System.out.println("filename = " + aURL.getFile()); ///docs/books/tutorial/index.html?name=networking
System.out.println("ref = " + aURL.getRef()); //DOWNLOADING
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment