O'Reilly logo

Ivor Horton's Beginning Java®, Java 7 Edition by Ivor Horton

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 8

Understanding Streams

WHAT YOU WILL LEARN IN THIS CHAPTER

  • What a stream is and what the main classes that Java provides to support stream operations are
  • What stream readers and writers are and what they are used for
  • How to read data from the keyboard
  • How to format data that you write to the command line

This is the first of five chapters devoted to input and output. This chapter introduces streams, and deals with keyboard input and output to the command line. In subsequent chapters you learn how to work with files.

STREAMS AND INPUT/OUTPUT OPERATIONS

Streams are fundamental to input and output in your programs in the most instances. The package that supports stream input/output primarily is java.io but other packages such as java.nio.file define stream classes, too. The java.io defines a large number of classes and interfaces, many of which have a significant number of methods. It is quite impractical to go into them all in detail in this book so my strategy in this and in the following chapters discussing file I/O is to take a practical approach. I provide an overall grounding in the concepts and equip you with enough detailed knowledge of the classes involved to enable you to do a number of specific, useful, and practical things in your programs. These are:

  • To be able to read data from the keyboard
  • To be able to write formatted output to a stream, such as System.out
  • To be able to read and write files containing strings and basic types of data
  • To be able to read ...

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