30 likes | 154 Views
Chapter 8: Understanding Streams. Understanding Streams. JDK 1.4 introduce a new way of handling primitive data types defined in java.nio & java.nio.channels packages A stream is a sequence of bytes The main reason for using streams is to make your program independent of the device involved
E N D
Understanding Streams • JDK 1.4 introduce a new way of handling primitive data types defined in java.nio & java.nio.channels packages • A stream is a sequence of bytes • The main reason for using streams is to make your program independent of the device involved • Two types • Binary • Character • The package java.io contains two main classes InputStream and OutputStream • InputStream has seven direct classes (Audio, File, Object, Sequence, ByteArray, Pipelined, Filter) • The FilterInputStream has further nine direct classes. One of them is BufferedInputStream (for efficient I/O)
Understanding Streams (cont.) • OutputStream has five direct classes (File, Object, ByteArray, Piped, Filter). • Stream readers and Writers are objects that can read and write byte streams as character streams • Reader has sic derived classes (InputSteam, Buffered, Filter, Piped, CharArray, String) • Ex: BufferedReader keyboard = new BufferedReader (new InputStreamReader(System.in)) • Getting data from the keyboard using the StreamTokenizer class • Methods suck as nextToken() returns int value and it can be TT_NUMBER, TT_WORD, TT_EOF, TT_EOL • Ex: FormatedInput.java & TestFormattedInput.java • Ex: FormattedWriter & TestedFormattedWriter