17.5. The URL Class
The URL class provides simple access to URLs. The class automatically parses a string for you, letting you retrieve the protocol (e.g., http), host (e.g., java.sun.com), port (e.g., 80), and filename (e.g., /reports/earnings.html) separately. The URL class also provides an easy-to-use interface for reading remote files.
Reading from a URL
Although writing a client to explicitly connect to an HTTP server and retrieve a URL was quite simple, this task is so common that the Java programming language provides a helper class: java.net.URL. We saw this class when we looked at applets (see Section 9.5, “Other Applet Methods”): a URL object of this type that needed to be passed to getAppletContext().showDocument. However, the URL ...
Get Core Web Programming, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.