O'Reilly logo

Java I/O, 2nd Edition by Elliotte Rusty Harold

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 5. Network Streams

From its first days, Java, more than any other common programming language, has had the network in mind. Java is the first programming language to provide as much support for network I/O as it does for file I/O, perhaps even more (Java’s URL, URLConnection, Socket, and ServerSocket classes are all fertile sources of streams). The exact type of the stream used by a network connection is typically hidden inside the undocumented sun classes. Thus, network I/O relies primarily on the basic InputStream and OutputStream methods, which you can wrap with any higher-level stream that suits your needs: buffering, cryptography, compression, or whatever your application requires.

URLs

The java.net.URL class represents a Uniform Resource Locator such as http://www.cafeaulait.org/books/javaio2/. Each URL unambiguously identifies the location of a resource on the Internet. The URL class has six constructors. All are declared to throw MalformedURLException, a subclass of IOException.

public URL(String url) throws MalformedURLException public URL(String protocol, String host, String file) throws MalformedURLException public URL(String protocol, String host, int port, String file) throws MalformedURLException public URL(String protocol, String host, int port, String file, URLStreamHandler handler) throws MalformedURLException public URL(URL context, String url) throws MalformedURLException public URL(URL context, String url, URLStreamHandler handler) throws MalformedURLException ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required