java4 - COP 3503 Computer Science II Java Notes#4 I/O in...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Introduction In the previous three sections of Java notes you were introduced to the basics of classes and methods in the Java language. This set of notes examines how basic I/O in Java is handled. The Basics At the highest level Java makes a distinction between the stream classes which handle binary 8-bit quantities, and the reader/writer classes which manipulate string and 16-bit Unicode character values. Underneath each of these classes is a vast array of subclasses (more than 40 by last count) which actually handle the I/O. A stream is simply an object for transmitting or retrieving 8-bit (byte) values with the emphasis placed on the action of reading or writing rather than on the data itself. A file is a collection of items stored on an external device and can be accessed in several different fashions. For example, a FileStream provides the capability of accessing the data values which are in a file but it does not actually hold any of the file contents. A stream is always a pipeline for transmitting 8-bit values, however, much of the functionality provided by the different stream abstractions in Java is intended to allow the programmer to think in terms of higher level units such as, transmitting strings or integers or object values, instead of their 8-bit internal representations. For example, the method readInt( ) which is found in the class DataInputStream processes four 8-bit values in the process of reading a single 32-bit integer value. Java supports two independent, but largely parallel, I/O systems. The hierarchy rooted in the two classes InputStream and OutputStream are used to read and write 8-bit quantities. Until Unicode becomes much more prevalent the parallel hierarchy rooted in the two classes Reader and Writer will be less commonly used than the previous two classes. In this set of notes, we will focus first on the stream classes and then on the reader/writer classes. The differences in the various input stream classes are seen more readily if they are divided into two broad categories, those classes which are tied to a COP 3503 – Java Notes #4 - 1 COP 3503 – Computer Science II – Java Notes #4 I/O in Java
Background image of page 1

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

View Full Document Right Arrow Icon
physical input source and those which read from input streams which are virtual . The virtual streams depend upon a second input stream for the actual reading operations but in some way extend the functionality of the input stream. For example such a class might extend the functionality of the read operation by allowing values in the stream to be unconsumed (i.e., pushed back to the source) if desired. We will not look at the virtual stream classes. The physical input source classes read values from byte arrays, files, or pipes. We will focus here, on the file as the input source.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 13

java4 - COP 3503 Computer Science II Java Notes#4 I/O in...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online