Tuesday, August 3, 2010

File Streams


There are four types of streams: InputStream, OutputStream, Reader, and Writer.
1.        Reader. A stream to read characters.
2.        Writer. A stream to write characters.
3.        InputStream. A stream to read binary data.
4.        OutputStream. A stream to write binary data.
1. Reading Binary Data
You use an InputStream to read binary data.
InputStream
  |
  +-- FileInputStream 
  |
  +-- BufferedInputStream
1.        FileInputStream enables easy reading from a file.
2.        BufferedInputStream provides data buffering that improves performance.
3.        The ObjectInputStream class is used in object serialization.

2. Writing Binary Data
The OutputStream abstract class represents a stream for writing binary data
OutputStream
  |
  +--FileOutputStream
  |
  +--BufferedOutputStream. 
  |
  +--ObjectOutputStream
1.        FileOutputStream provides a convenient way to write to a file.
2.        BufferedOutputStream provides better performance.
3.        ObjectOutputStream class plays an important role in object serialization.
 3. OutputStream
The OutputStream class defines three write method overloads, which are mirrors of the read method overloads in InputStream:
1.        The first overload writes the lowest 8 bits of the integer b to this OutputStream.
2.        The second writes the content of a byte array to this OutputStream.
3.        The third overload writes length bytes of the data starting at offset offset.
     close() method closes the OutputStream.
      flush() method forces any buffered content to be written out to the sink.
S

No comments:

Post a Comment