Java Reference
In-Depth Information
CHAPTER 8
Input and Output
Oftentimes in applications, there is a requirement to obtain and manipulate the I/O ter-
minals. In today's operating systems, that usually means file access and network con-
nectivity. In previous releases, Java was slow to adopt a good file and network frame-
work in order to maintain universal compatibility. Standing true to its roots of write
once, read everywhere, a lot of the original file I/O and network connectivity needed to
be simple and universal. Since the release of Java 7, developers have been taking ad-
vantage of much better I/O APIs.
The file and network I/O has evolved over the years into a much better framework
for handling files, network scalability, and ease of use,. As of the network input output
version 2 API (NIO.2), Java has the capability of monitoring folders, accessing OS-de-
pendent methods, and create scalable asynchronous network sockets. This is in addition
to the already robust library for handling input and output streams, and serializing (and
deserializing) object information.
In this chapter, we cover recipes that demonstrate different input and output pro-
cesses. You learn about serialization of files, sending files over the network, file manipu-
lation, and much more. After reading the recipes in this chapter, you will be armed with
the capability to develop applications containing sophisticated input and output tasks.
STREAMS AND THE DECORATOR PATTERN
I/O streams are the foundation of most of the Java I/O and include a plethora
of ready-made streams for any occasion, but they are very confusing to use if
some context is not provided. A stream (like a river) represents an inflow/out-
flow of data. Think about it this way. When you type, you create a stream of
characters that the system receives (input stream). When the system produces
sounds, it sends them to the speaker (output stream). The system could be re-
Search WWH ::




Custom Search