10.1 An Overview of Streams and File I/O

Fish say, they have their Stream and Pond,

But is there anything Beyond?

—RUPERT BROOKE, Heaven

In this section, we give you a general introduction to file I/O. In particular, we explain the difference between text files and binary files. The Java syntax for file I/O statements is given in subsequent sections of this chapter.

The Concept of a Stream

You are already using files to store your Java classes and programs, your music, your pictures, and your videos. You can also use files to store input for a program or to hold output from a program. In Java, file I/O, as well as simple keyboard and screen I/O, is handled by streams. A stream is a flow of data. The data might be characters, numbers, or bytes ...

Get Java: An Introduction to Problem Solving and Programming, 8th 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.