0% found this document useful (0 votes)
48 views23 pages

The Java

Streams allow data to move between programs through input and output streams. Java provides a hierarchy of stream classes including InputStream, OutputStream, Reader and Writer. InputStreams read data from a source and OutputStreams write data to a destination. Common stream classes include FileInputStream, FileOutputStream, BufferedInputStream, BufferedOutputStream, DataInputStream and DataOutputStream. Filtered streams allow streams to be chained together for additional functionality.

Uploaded by

Divya Mathews
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views23 pages

The Java

Streams allow data to move between programs through input and output streams. Java provides a hierarchy of stream classes including InputStream, OutputStream, Reader and Writer. InputStreams read data from a source and OutputStreams write data to a destination. Common stream classes include FileInputStream, FileOutputStream, BufferedInputStream, BufferedOutputStream, DataInputStream and DataOutputStream. Filtered streams allow streams to be chained together for additional functionality.

Uploaded by

Divya Mathews
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 23

INPUT/OUTPUT STREAMS

Streams
Sequence of bytes that travel from a source to a destination over a communication path. Streams source-A program which is writing into the stream. Streams destination-A program which is reading from a stream. Two major classes of byte streams 1. InputStream 2.OutputStream

The java.io Class Hierarchy


InputStream,OutputStream,Reader and Writer are the major components of this hierarchy. The InputStream and OutputStream classes have complementary subclasses. The InputStream classes perform the input and the OutputStream classes perform the output.

The InputStream class


FilterInputStream BufferedInputStream DataInputStream LineNumberInputStream PushbackInputStream ByteArrayInputStream FileInputStream ObjectInputStream ObjectInputStream GetField(nested) PipedInputStream SequenceInputStream StringBufferInputStream

The OutputStream class


FilterOutputStream BufferedOutputStream DataOutputStream PrintStream ByteArrayOutputStream FileOutputStream ObjectOutputStream ObjectOutputStream PutField(nested) PipedOutputStream

Reader
BufferedReader LineNumberReader CharArrayReader FilterReader PushbackReader InputStreamReader FileReader PipedReader StringReader

Writer
BufferedWriter CharArrayWriter FilterWriter OutputStreamWriter FileWriter PipedWriter PrintWriter StringWriter

File
RandomAccessFile FileDescriptor FilePermission ObjectStreamClass ObjectStreamField SerializablePermission StreamTokenizer

The java.io Interfaces


DataInput and DataOutput interfaces ObjectInput and ObjectOutput interfaces ObjectInputValidation interfaces ObjectStreamConstants interfaces Serializable interface Externalizable interface Replaceable interface Resolvable interface FileFilter interface FilenameFilter interface

The InputStream Class


The read() Method The available() Method The close() Method Markable Streams These are streams that provide a capability to mark a position in the stream and then reset the stream so that it can be reread from the marked position. The skip() Method

The OutputStream Class


The write() Method It allows byte to be written to the output stream. It provides three overloaded forms to write an integer, an array of bytes, or a sub array of bytes to an OutputStream object. The flush() Method The flush() Method causes any buffered data to be immediately written to the OutputStream. The close() Method

Byte Array I/O


Java supports ByteArrayInputStream and ByteArrayOutputStream Classes. These classes use memory buffers as the source and destination of the input and output streams. ByteArrayInputStream Classes It creates an input stream from a memory buffer. It provide two constructors which use byte argument to create the input stream. It overrides the read(),skip(),available() methods of InputStream.

ByteArrayOutputStream Class
It creates an output stream on a byte array. It provide toByteArray() and toString() Methods. It also provide two constructors. The reset() method is used to reset the output buffer. The size() method returns the current number of bytes that have been written to the buffer. The writeTo() method write the contents of the output buffer to the specified output stream. StringBufferInputStream Class It uses StringBuffer to store input data.

File I/O
Java supports stream based file input and output through the File, FileDescriptor, FileInputStream and FileOutputStream Classes. The File Class It is used to access file and directory objects. It provide constructors for creating files and directories. It provide numerous access methods. Directory methods allow directories to be created, deleted, renamed and listed.

The FileDescriptor Class


It provides access to the file descriptors. It provide valid() method, which is used to determine whether a file descriptor object is currently valid. The FileInputStream Class It allows input to be read from a file in the form of a stream. It overrides the methods of the InputStream class and provides two new methods, finalize() and getFD().

The FileOutputStream Class It allows output to be written to a file stream. The SequenceInputStream Class It is used to combine two or more input streams into a single input stream. It does not introduce any new access methods. It provide two constructors.

Filtered I/O
It provide the capability to filter I/O in a number of useful ways. The FilterInputStream Class It provide a capability to create one stream from another. It uses the in variable, which is used to maintain a separate object of class InputStream.

The FilterOutputStream Class


It maintains an object of class OutputStream as an output variable.

Buffered I/O
When a program reads from the input stream, the input bytes are read from the input buffer. Input buffering is used to speedup overall stream input processing. Output buffering is performed similar manner to input buffering.

The BufferedInputStream Class


It supports input buffering by automatically creating and maintaining a buffer for a designated input stream. It also provide two constructors. It overrides the access methods of InputStream Class.

The BufferedOutputStream class


It perform output buffering in a manner that is similar to that of BufferedInputStream class.

PushbackInputStream
It is a filter that push a byte that was previously read back on to the input stream so that it can be reread. It is commonly used with parsers. It allows only a single byte to be pushed back. The pushback character is stored in a variable named pushBack. This class introduces a new method called unread() method.

The LineNumberInputStream Class


It provides a capability for keeping track of input line numbers. This class provides two new methods to support line number processing The setLineNumber() Method The getLineNumber() Method Data I/O Implements DataInput and DataOutput interfaces. It allows primitive data types to be read from written to a stream.

DataInputStream Class
It provides the capability to read objects and primitive types from an input stream.
readBoolean() readByte() readChar() readDouble() readFloat() readFully() readInt() readLine() readlong()

DataOutputStream Class
It allows arbitrary objects and primitive data to be written to an output stream. It is an output filter and can be combined with any output filtering streams.

The PrintStream Class


The System.Out object is an instance of the PrintStream Class. It provides three methods print() println() checkError()

You might also like