Posted in Java
import java.net.MalformedURLException; import java.net.URL; /** * * @author Azhar */ public class parseUrl { public static void main(String[] args) throws MalformedURLException { URL url = new URL("http://example.com:80/docs/books/tutorial/index.html?name=networking#DOWNLOADING"); System.out.println("protocol: " + url.getProtocol()); System.out.println("authority: " + url.getAuthority()); System.out.println("host: " + url.getHost()); System.out.println("port: " + url.getPort()); System.out.println("path:" + url.getPath()); System.out.println("query: " + url.getQuery()); System.out.println("filename: " + url.getFile()); System.out.println("ref: " + url.getRef()); } }Ketika di run, program tersebut akan menghasilkan output sebagai berikut:
protocol: http authority: example.com:80 host: example.com port: 80 path:/docs/books/tutorial/index.html query: name=networking filename: /docs/books/tutorial/index.html?name=networking ref: DOWNLOADINGSumber: Oracle Documentation Semoga bermanfaat.