• For each type of source and destination in java.io package oracle given a separate class.

InputStream Class:

  • ByteArrayInputStream
  • FileInputStream
  • FilterInputStream
    • BufferedInputStream
    • DataInputStream
    • LineNumberInputStream
    • PushbackInputStream
  • ObjectInputStream
  • PipeInputStream
  • SequenceInputStream
  • StringBufferInputStream

IputStream Class Methods:

  • Since InputStream class is the super class for all input stream classes. It has below methods with general implementation for all sub classes.

1.public int available() throws IOException :

  • Checking available bytes to read.

2.public abstract int read() throws IOException :

  • Reading byte-by-byte.

3.public int read(byte[] b) throws IOException :

  • Reading all  bytes.

4.public int read(byte[] b, int off, int length) throws IOException :

  • Reading selected range of bytes.

5.public boolean markSupported() :

  • Checking is this Stream supports marking.

6.public void mark(int readLimit) :

  •  Marking current position of stream.

7.public void reset() throws IOException :

  • Placing the control at marked place.

8.public long skip(long n) throws IOException :

  • Skip reading given range of bytes.

9.public void close() throws IOException :

  • Closing the stream.

OutputStream Class:

  • ByteArrayOutputStream
  • FileOutputStream
  • FilterOutputStream
    • BufferedOutputStream
    • DataOutputStream
    • PrintStream
  • ObjectOutputStream
  • PipeOutputStream

OutputStream class methods:

  • Since OutputStream is the super class of all binary output stream classes it has below method with general implementation for all sub classes.

1.public abstract void write(int i)throws IOException:

  • Writing one by at time to an output stream.

2.public void write(byte[] b) throws IOException :

  • Writing stream of bytes to an output stream.

3.public void write(byte []b , int off, int length) throws IOException :

  • Writing range of stream of bytes to an output stream.

4.public void flush() throws IOException :

  • Flush all bytes to destination from output Stream.

5.public void close() throws IOException :

  • Close output stream.

FileInputStream and FileOutputStream:

  • These classes are used to read and write data as byte from File.
  • Basically these two streams are used as basic data source and destination for other streams.

DataInputStream and DataOutputStream:

  • These two classes are used to read and write data as primitive data.
  • Basically these two streams are used to add capability to another input stream and output stream to read and write data as primitive types.

ObjectInputStream and ObjectOutputStream:

BufferedInputStream and BufferedOutputStream:

  •  These two classes are used to read and write data as buffers.
  • Basically these two streams are used to improve reading and writing performance of other streams.

SequenceInputStream:

  • This class is used to read data from multiple InputStreams Sequentially.

 PrintStream: 

  • PrintStream class is filter output stream class .
  • Its adds functionality to another OutputStream, namely the ability to print representations of various data values conveniently.


Basic steps to perform IO Operations:

  • Create stream class object based on source and destination.
  • Call read() method to read data from the source.
  • Call write() method to write data to the destination.
For instance , to perform IO Operations on files we must create
  • FileInputStream
  • FileOutputStream or
  • FileReader
  • FileWriter  Streams class objects
-
You might like:

Instance Of Java

We will help you in learning.Please leave your comments and suggestions in comment section. if you any doubts please use search box provided right side. Search there for answers thank you.
«
Next
Newer Post
»
Previous
Older Post

No comments

Leave a Reply

Select Menu