Skip to Content
Learning Java, 5th Edition
book

Learning Java, 5th Edition

by Marc Loy, Patrick Niemeyer, Daniel Leuck
March 2020
Beginner
515 pages
15h
English
O'Reilly Media, Inc.
Content preview from Learning Java, 5th Edition

Chapter 11. Networking and I/O

In this chapter, we continue our exploration of the Java API by looking at many of the classes in the java.io and java.nio packages. These packages offer a rich set of tools for basic I/O (input/output) and also provide the framework on which all file and network communication in Java is built. Figure 11-1 shows the class hierarchy of these packages. We’ll only cover a selection of this hierarchy, but you can see that it is quite broad. Once you have a handle on local file I/O, we’ll add the java.net package and look at some basic networking concepts. (We’ll tackle the most popular of networking environments—the web—in Chapter 12.)

We’ll start by looking at the stream classes in java.io, which are subclasses of the basic InputStream, OutputStream, Reader, and Writer classes. Then we’ll examine the File class and discuss how you can read and write files using classes in java.io. We also take a quick look at data compression and serialization. Along the way, we’ll also introduce the java.nio package. The NIO package (or “new” I/O) adds significant functionality tailored for building high-performance services and in some cases simply provides newer, better APIs that can be used in place of some java.io features.1

Streams

Most fundamental I/O in Java is based on streams. A stream represents a flow of data with (at least conceptually) a writer at one end and a reader at the other. When you are working with the java.io package to perform terminal input ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning Java, 4th Edition

Learning Java, 4th Edition

Patrick Niemeyer, Daniel Leuck
Learning Java, 6th Edition

Learning Java, 6th Edition

Marc Loy, Patrick Niemeyer, Daniel Leuck
Java in a Nutshell, 7th Edition

Java in a Nutshell, 7th Edition

Benjamin J. Evans, David Flanagan
Head First Java, 2nd Edition

Head First Java, 2nd Edition

Kathy Sierra, Bert Bates

Publisher Resources

ISBN: 9781492056263Errata PageSupplemental Content