Various I/O Stream Classes                       http://improvejava.blogspot.in/   1
ObjectivesOn completion of this period, you would be able to learn   • Concept of streams   • Various input and output str...
RecapIn the previous classes, you have studied about   exception handling mechanism in java• Types of exceptions in java  ...
Concept of Stream• Java performs I/O through streams•A stream is an abstraction that either produces or consumesinformatio...
Concept of StreamThe following figure gives the relationship of java program withI/O devices  Key Board                   ...
Concept of Stream• The Fig. 47.1 shows in Java all I/O devices may be used withstream•For example, the same methods that a...
Concept of Streams• Input refers to flow of data into a program• Output refers to flow of data out of a program as  shown ...
Concept of Streams                        Contd..• I/O operations are complex to understand• But more flexible and powerfu...
Various I/O Stream Classes• java.io package defines I/O in terms of streams• Two types of Streams   1. Byte streams      •...
Various I/O Stream Classes• The following diagrams show the class hierarchies of  the stream classes   •   InputStream   •...
Hierarchy of InputStream classes                     Object                   InputStream FileInputStream                 ...
Hierarchy of OutputStream Classes                    Object                OutputStream FileOutputStream                Ob...
Hierarchy of Reader Classes                      Object                        ReaderBufferedReader                       ...
Hierarchy of Writer Classes                     Object                       WriterBufferedWriter                         ...
Simple Input and Output Streams• FileInputStream and FileOutputStream   • Used to read data from or write data to a file o...
Simple Input and Output Streams• ByteArrayInputStream and ByteArrayOutputStream   • Reads data from or writes data to a by...
Filtered Streams• FilterInputStream and FilterOutputStream are subclasses of  InputStream and OutputStream• Both are abstr...
Filtered Streams• BufferedInputStream and BufferedOutputStream   • This is an efficient stream that buffers data while rea...
Summary• Flow of bits of information either into the program  or from the program to and from• Various input and output de...
Quiz1. Which of the following is not Byte streams   A.   Input Stream   B.   Output Stream   C.   Reader   D.   None      ...
Quiz2. Streams is ordered sequences of data that have a    source or a destination   A. True   B. False                   ...
Frequently Asked Questions1. Explain the concept of Streams2. Explain the various input output stream classes             ...
Upcoming SlideShare
Loading in...5
×

Various io stream classes .47

570

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
570
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
7
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Various io stream classes .47

  1. 1. Various I/O Stream Classes http://improvejava.blogspot.in/ 1
  2. 2. ObjectivesOn completion of this period, you would be able to learn • Concept of streams • Various input and output stream classes http://improvejava.blogspot.in/ 2
  3. 3. RecapIn the previous classes, you have studied about exception handling mechanism in java• Types of exceptions in java http://improvejava.blogspot.in/ 3
  4. 4. Concept of Stream• Java performs I/O through streams•A stream is an abstraction that either produces or consumesinformation•A stream is linked to an I/O device by Java I/O system•All streams behave in the same manner, even if the actualphysical device they are linked to differ•Thus, same I/O classes and methods can be applied to anytype of device•For example, the same methods that are used to write consolecan also be used to write to a disk file http://improvejava.blogspot.in/ 4
  5. 5. Concept of StreamThe following figure gives the relationship of java program withI/O devices Key Board Screen Mouse printer Java Memory Memory Program Disk Disk Network Network Fig. 47.1 Relationship of Java programs with I/O devices http://improvejava.blogspot.in/ 5
  6. 6. Concept of Stream• The Fig. 47.1 shows in Java all I/O devices may be used withstream•For example, the same methods that are used to write consolecan also be used to write to a disk file• java implements streams within class hierarchies defined injava.io. package http://improvejava.blogspot.in/ 6
  7. 7. Concept of Streams• Input refers to flow of data into a program• Output refers to flow of data out of a program as shown in Fig. 47.1 http://improvejava.blogspot.in/ 7
  8. 8. Concept of Streams Contd..• I/O operations are complex to understand• But more flexible and powerful• Developers have focused their attention for non keyboard oriented data handling• Developers wanted to perform platform independent I/O, hence the complexity http://improvejava.blogspot.in/ 8
  9. 9. Various I/O Stream Classes• java.io package defines I/O in terms of streams• Two types of Streams 1. Byte streams • 8 bits, binary data-based • Examples: InputStream and OutputStream classes 2. Character streams • 16 bits, text-based • Examples: Reader and Writer classes http://improvejava.blogspot.in/ 9
  10. 10. Various I/O Stream Classes• The following diagrams show the class hierarchies of the stream classes • InputStream • OutputStream • Reader • Writer http://improvejava.blogspot.in/ 9CM604.47 10
  11. 11. Hierarchy of InputStream classes Object InputStream FileInputStream SequenceInpuStreamPipedInpuStream ObjectInputStream ByteArrayInputStream StringBufferInputStream FilterInpuStream DataInputStreamBufferedInpuStream PushBackInputSteam 11 Fig. 47.2 DataInput http://improvejava.blogspot.in/
  12. 12. Hierarchy of OutputStream Classes Object OutputStream FileOutputStream ObjectOutputStreamPipedOutputStream ByteArrayOutputStream FilterOutpuStream DataOutputStreamBufferedOutpuStream PushBackOutputSteam Fig. 47.3 DataOutput http://improvejava.blogspot.in/ 12
  13. 13. Hierarchy of Reader Classes Object ReaderBufferedReader StringReaderCharArrayReader PipeReader InputStreamReader FilterReader Fig. 47.4 FileReader PushBackReader http://improvejava.blogspot.in/ 13
  14. 14. Hierarchy of Writer Classes Object WriterBufferedWriter PrintWriterCharArrayWriter StringWriter FilterWriter PipeWriter FileReader OutputStreamWriter Fig No 47.5 14 FileWriter http://improvejava.blogspot.in/
  15. 15. Simple Input and Output Streams• FileInputStream and FileOutputStream • Used to read data from or write data to a file on the native file system• PipedInputStream and PipedOutputStream • Implements the input and output components of a pipe • Pipes are used to channel the output from one program (or thread or code block) into the input of another • A PipedInputStream must be connected to a PipedOutputStream and vice versa http://improvejava.blogspot.in/ 15
  16. 16. Simple Input and Output Streams• ByteArrayInputStream and ByteArrayOutputStream • Reads data from or writes data to a byte array in memory• SequenceInputStream • Concatenates multiple input streams into one input stream• StringBufferInputStream • Allows programs to read from a StringBuffer as if it were an input stream http://improvejava.blogspot.in/ 16
  17. 17. Filtered Streams• FilterInputStream and FilterOutputStream are subclasses of InputStream and OutputStream• Both are abstract classes• These classes defines the interface for filtered streams• Filtered streams process the data as its being read or written• DataInputStream and DataOutputStream • Reads or writes primitive Java data types in a machine independent format http://improvejava.blogspot.in/ 17
  18. 18. Filtered Streams• BufferedInputStream and BufferedOutputStream • This is an efficient stream that buffers data while reading or writing• LineNumberInputStream • An input stream that keeps track of line numbers while reading• PushbackInputStream • An input stream with a one-byte pushback buffer PrintStream • An output stream with convenient printing methods http://improvejava.blogspot.in/ 18
  19. 19. Summary• Flow of bits of information either into the program or from the program to and from• Various input and output devices• Stream is a logical entity that either produces or consumes information• Two types of Streams 1. Byte streams 2. Character streams http://improvejava.blogspot.in/ 19
  20. 20. Quiz1. Which of the following is not Byte streams A. Input Stream B. Output Stream C. Reader D. None http://improvejava.blogspot.in/ 20
  21. 21. Quiz2. Streams is ordered sequences of data that have a source or a destination A. True B. False http://improvejava.blogspot.in/ 21
  22. 22. Frequently Asked Questions1. Explain the concept of Streams2. Explain the various input output stream classes http://improvejava.blogspot.in/ 22
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×