• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Various io stream classes .47
 

Various io stream classes .47

on

  • 336 views

 

Statistics

Views

Total Views
336
Views on SlideShare
336
Embed Views
0

Actions

Likes
0
Downloads
6
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Various io stream classes .47 Various io stream classes .47 Presentation Transcript

    • 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 stream classes http://improvejava.blogspot.in/ 2
    • RecapIn the previous classes, you have studied about exception handling mechanism in java• Types of exceptions in java http://improvejava.blogspot.in/ 3
    • 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
    • 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
    • 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
    • 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
    • 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
    • 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
    • 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
    • Hierarchy of InputStream classes Object InputStream FileInputStream SequenceInpuStreamPipedInpuStream ObjectInputStream ByteArrayInputStream StringBufferInputStream FilterInpuStream DataInputStreamBufferedInpuStream PushBackInputSteam 11 Fig. 47.2 DataInput http://improvejava.blogspot.in/
    • Hierarchy of OutputStream Classes Object OutputStream FileOutputStream ObjectOutputStreamPipedOutputStream ByteArrayOutputStream FilterOutpuStream DataOutputStreamBufferedOutpuStream PushBackOutputSteam Fig. 47.3 DataOutput http://improvejava.blogspot.in/ 12
    • Hierarchy of Reader Classes Object ReaderBufferedReader StringReaderCharArrayReader PipeReader InputStreamReader FilterReader Fig. 47.4 FileReader PushBackReader http://improvejava.blogspot.in/ 13
    • Hierarchy of Writer Classes Object WriterBufferedWriter PrintWriterCharArrayWriter StringWriter FilterWriter PipeWriter FileReader OutputStreamWriter Fig No 47.5 14 FileWriter http://improvejava.blogspot.in/
    • 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
    • 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
    • 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
    • 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
    • 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
    • Quiz1. Which of the following is not Byte streams A. Input Stream B. Output Stream C. Reader D. None http://improvejava.blogspot.in/ 20
    • Quiz2. Streams is ordered sequences of data that have a source or a destination A. True B. False http://improvejava.blogspot.in/ 21
    • Frequently Asked Questions1. Explain the concept of Streams2. Explain the various input output stream classes http://improvejava.blogspot.in/ 22