Java-InputStream and OutputStream Classes

InputStream and OutputStream Classes

The InputStream and OutputStream classes and their subclasses are used for dealing with data in binary format. The important methods in these two classes are described in following tables :

Important Methods in the OutputStream Class

Methods Usage
write( ) To write a byte to the outputstream
write(byte b[ ]) To write all bytes in the array b to the output stream
write(byte b[ ], int n, int m) To write m bytes from array b starting from n’th byte
close( ) To close the output stream
flush( ) To flush (i.e. clear) the output stream

Important Methods in the InputStream Class

Methods Usage
read( ) To read a byte from the input stream
read(byte b[ ]) To read an array of b.length bytes into array b
read(byte b[ ], int n, int m) To read m bytes into b starting from n’th byte
available( ) To give the number of bytes available in the input
skip(n) To skip over and discard n bytes from the input stream
reset( ) To go back to the beginning of the stream
close( ) To close the input stream

Important Subclasses of OutputStream Class

Name of the Class Functionality
BufferedOutputStream Buffering output
ByteArrayOutputStream Writing to an array
FilterOutputStream Filtering the output
FileOutputStream Writing to a file
PrintStream Outputs the unicode format of the primitive types to the Console
PipedOutputStream Writing to a pipe
DataOutputStream Writing primitive data types

Important Subclasses of InputStream Class

Name of the Class Functionality
BufferedInputStream Buffering input
LineNumberInputStream Keeping track of how many lines are read
ByteArrayInputStream Reading from an array
FileInputStream Reading from a file
FilterlnputStream Filtering the input
PushbackInputStream Pushing back a byte to the stream
PipedlnputStream Reading from a pipe
StringBufferInputStream Reading from a String
DataInputStream Reading primitive types

Leave a Comment