IO_Stream_11 - Input and Output in Java 1 Introduction The...

Info icon This preview shows pages 1–7. Sign up to view the full content.

1 Input and Output in Java
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

2 Introduction The java.io package contains classes that perform input and output. In Java, I/O classes are differentiated according to the type of data being read or written. Byte oriented and numeric data is written with output streams and read with input streams . Character data, that is text, is written with writers and read with readers .
Image of page 2
Readers and Writers operate much like streams but understand how to convert to and from various external character sets like Big-5 Chinese or MacRoman into Unicode. Whether you use streams or readers and writers depends on the type of data you're dealing with. The two main stream classes are java.io.InputStream and java.io.OutputStream. The two main reader and writer classes are java.io.Reader and java.io.Writer These are abstract base classes for many different subclasses with more specialized abilities. 3 Introduction (cont…)
Image of page 3

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

4 Streams Java programs perform I/O through streams. A stream is an abstraction that either produces or consumes information. A stream is linked to a physical device by the Java I/O system. An input stream can abstract many different kinds of input: from a disk file, a keyboard, or a network socket. Likewise, an output stream may refer to the console, a disk file, or a network connection. Streams are a clean way to deal with input/output without having every part of your code understand the difference between a keyboard and a network, for example. Java implements streams within class hierarchies defined in the java.io package
Image of page 4