SlideShare a Scribd company logo
Various I/O Stream Classes




                       http://improvejava.blogspot.in/   1
Objectives

On completion of this period, you would be able to
 learn
   • Concept of streams
   • Various input and output stream classes




                      http://improvejava.blogspot.in/   2
Recap

In 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 consumes
information
•A stream is linked to an I/O device by Java I/O system
•All streams behave in the same manner, even if the actual
physical device they are linked to differ
•Thus, same I/O classes and methods can be applied to any
type of device
•For example, the same methods that are used to write console
can also be used to write to a disk file

                      http://improvejava.blogspot.in/           4
Concept of Stream
The following figure gives the relationship of java program with
I/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 with
stream
•For example, the same methods that are used to write console
can also be used to write to a disk file
• java implements streams within class hierarchies defined in
java.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                    SequenceInpuStream


PipedInpuStream                        ObjectInputStream


 ByteArrayInputStream               StringBufferInputStream

                     FilterInpuStream

                     DataInputStream
BufferedInpuStream                           PushBackInputSteam
                                                                  11
       Fig. 47.2         DataInput
                              http://improvejava.blogspot.in/
Hierarchy of OutputStream Classes
                    Object


                OutputStream

 FileOutputStream                ObjectOutputStream


PipedOutputStream               ByteArrayOutputStream




                    FilterOutpuStream

                   DataOutputStream
BufferedOutpuStream               PushBackOutputSteam
       Fig. 47.3     DataOutput
                             http://improvejava.blogspot.in/   12
Hierarchy of Reader Classes
                      Object


                        Reader

BufferedReader                                   StringReader


CharArrayReader                                      PipeReader


  InputStreamReader                                   FilterReader



                        Fig. 47.4
      FileReader                                     PushBackReader
                   http://improvejava.blogspot.in/                    13
Hierarchy of Writer Classes
                     Object


                       Writer

BufferedWriter                             PrintWriter


CharArrayWriter                                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
Quiz

1. Which of the following is not Byte streams

   A.   Input Stream
   B.   Output Stream
   C.   Reader
   D.   None




                        http://improvejava.blogspot.in/   20
Quiz

2. Streams is ordered sequences of data that have a
    source or a destination

   A. True
   B. False




                   http://improvejava.blogspot.in/    21
Frequently Asked Questions

1. Explain the concept of Streams
2. Explain the various input output stream classes




                   http://improvejava.blogspot.in/   22

More Related Content

PPT
Character stream classes introd .51
PPT
Character stream classes .52
PPT
Byte stream classes.49
PPT
Input output streams
PDF
Java Course 8: I/O, Files and Streams
PPTX
Understanding java streams
PPT
Java Streams
PPTX
L21 io streams
Character stream classes introd .51
Character stream classes .52
Byte stream classes.49
Input output streams
Java Course 8: I/O, Files and Streams
Understanding java streams
Java Streams
L21 io streams

What's hot (20)

PPT
Java IO Package and Streams
PDF
PPTX
Java Input Output (java.io.*)
PDF
Javaiostream
PDF
input/ output in java
PDF
Java I/o streams
PDF
java.io - streams and files
PPT
Java stream
PDF
32.java input-output
ODP
IO In Java
PPT
IO and serialization
PDF
Java IO
PPTX
Handling I/O in Java
PDF
PDF
Basic i/o & file handling in java
PPS
Files & IO in Java
PPTX
File Handling in Java Oop presentation
PDF
Java - File Input Output Concepts
PPTX
Reading and Writing Files
PPT
14 file handling
 
Java IO Package and Streams
Java Input Output (java.io.*)
Javaiostream
input/ output in java
Java I/o streams
java.io - streams and files
Java stream
32.java input-output
IO In Java
IO and serialization
Java IO
Handling I/O in Java
Basic i/o & file handling in java
Files & IO in Java
File Handling in Java Oop presentation
Java - File Input Output Concepts
Reading and Writing Files
14 file handling
 
Ad

Viewers also liked (18)

PPT
Unit v
PPT
Jedi Slides Intro2 Chapter12 Advanced Io Streams
DOCX
Nested classes in java
PPT
Inner classes9 cm604.28
PPTX
Inner classes
PDF
I/O in java Part 1
PPT
Inner classes ,annoumous and outer classes in java
PPT
Java API, Exceptions and IO
PPT
Java: Objects and Object References
PPT
Collections Framework
PDF
Java Inner Classes
PPT
JAVA Variables and Operators
PPT
JAVA OOP
PDF
Classes and Nested Classes in Java
PPT
Object and Classes in Java
PPT
Jsp/Servlet
PPT
Java Basics
PPS
Introduction to class in java
Unit v
Jedi Slides Intro2 Chapter12 Advanced Io Streams
Nested classes in java
Inner classes9 cm604.28
Inner classes
I/O in java Part 1
Inner classes ,annoumous and outer classes in java
Java API, Exceptions and IO
Java: Objects and Object References
Collections Framework
Java Inner Classes
JAVA Variables and Operators
JAVA OOP
Classes and Nested Classes in Java
Object and Classes in Java
Jsp/Servlet
Java Basics
Introduction to class in java
Ad

Similar to Various io stream classes .47 (20)

PPTX
CHAPTER 5 mechanical engineeringasaaa.pptx
PPTX
Input & output
PPTX
Chapter 13_m5JAVANOTESAPPLETS,INPUT.pptx
PDF
inputoutputstreams-140612032817-phpapp02.pdf
PPTX
Buffer and scanner
PPT
Java development development Files lectur6.ppt
PDF
Advanced programming ch2
PDF
Basic IO
PPTX
Spring MVC framework
PPS
Java session14
PPTX
Java programming Chapter 4.pptx
PPT
Byte arrayinputstream.50
PPTX
Stream In Java.pptx
PPTX
object oriented programming unit one ppt
PDF
Lecture 23
PPTX
Unit No 5 Files and Database Connectivity.pptx
PDF
CSE3146-ADV JAVA M2.pdf
PPTX
Diving into Sitecore Pipelines and Processors: Concepts, Customization, and B...
PPT
Itp 120 Chapt 19 2009 Binary Input & Output
PPTX
oop unit1.pptx
CHAPTER 5 mechanical engineeringasaaa.pptx
Input & output
Chapter 13_m5JAVANOTESAPPLETS,INPUT.pptx
inputoutputstreams-140612032817-phpapp02.pdf
Buffer and scanner
Java development development Files lectur6.ppt
Advanced programming ch2
Basic IO
Spring MVC framework
Java session14
Java programming Chapter 4.pptx
Byte arrayinputstream.50
Stream In Java.pptx
object oriented programming unit one ppt
Lecture 23
Unit No 5 Files and Database Connectivity.pptx
CSE3146-ADV JAVA M2.pdf
Diving into Sitecore Pipelines and Processors: Concepts, Customization, and B...
Itp 120 Chapt 19 2009 Binary Input & Output
oop unit1.pptx

More from myrajendra (20)

PPT
Fundamentals
PPT
Data type
PPTX
Hibernate example1
PPTX
Jdbc workflow
PPTX
2 jdbc drivers
PPTX
3 jdbc api
PPTX
4 jdbc step1
PPTX
Dao example
PPTX
Sessionex1
PPTX
Internal
PPTX
3. elements
PPTX
2. attributes
PPTX
1 introduction to html
PPTX
Headings
PPTX
Forms
PPT
PPTX
Views
PPTX
Views
PPTX
Views
PPT
Starting jdbc
Fundamentals
Data type
Hibernate example1
Jdbc workflow
2 jdbc drivers
3 jdbc api
4 jdbc step1
Dao example
Sessionex1
Internal
3. elements
2. attributes
1 introduction to html
Headings
Forms
Views
Views
Views
Starting jdbc

Various io stream classes .47

  • 1. Various I/O Stream Classes http://improvejava.blogspot.in/ 1
  • 2. Objectives On 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. Recap In the previous classes, you have studied about exception handling mechanism in java • Types of exceptions in java http://improvejava.blogspot.in/ 3
  • 4. Concept of Stream • Java performs I/O through streams •A stream is an abstraction that either produces or consumes information •A stream is linked to an I/O device by Java I/O system •All streams behave in the same manner, even if the actual physical device they are linked to differ •Thus, same I/O classes and methods can be applied to any type of device •For example, the same methods that are used to write console can also be used to write to a disk file http://improvejava.blogspot.in/ 4
  • 5. Concept of Stream The following figure gives the relationship of java program with I/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. Concept of Stream • The Fig. 47.1 shows in Java all I/O devices may be used with stream •For example, the same methods that are used to write console can also be used to write to a disk file • java implements streams within class hierarchies defined in java.io. package http://improvejava.blogspot.in/ 6
  • 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. 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. 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. 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. Hierarchy of InputStream classes Object InputStream FileInputStream SequenceInpuStream PipedInpuStream ObjectInputStream ByteArrayInputStream StringBufferInputStream FilterInpuStream DataInputStream BufferedInpuStream PushBackInputSteam 11 Fig. 47.2 DataInput http://improvejava.blogspot.in/
  • 12. Hierarchy of OutputStream Classes Object OutputStream FileOutputStream ObjectOutputStream PipedOutputStream ByteArrayOutputStream FilterOutpuStream DataOutputStream BufferedOutpuStream PushBackOutputSteam Fig. 47.3 DataOutput http://improvejava.blogspot.in/ 12
  • 13. Hierarchy of Reader Classes Object Reader BufferedReader StringReader CharArrayReader PipeReader InputStreamReader FilterReader Fig. 47.4 FileReader PushBackReader http://improvejava.blogspot.in/ 13
  • 14. Hierarchy of Writer Classes Object Writer BufferedWriter PrintWriter CharArrayWriter StringWriter FilterWriter PipeWriter FileReader OutputStreamWriter Fig No 47.5 14 FileWriter http://improvejava.blogspot.in/
  • 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. 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. 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. 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. 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. Quiz 1. Which of the following is not Byte streams A. Input Stream B. Output Stream C. Reader D. None http://improvejava.blogspot.in/ 20
  • 21. Quiz 2. Streams is ordered sequences of data that have a source or a destination A. True B. False http://improvejava.blogspot.in/ 21
  • 22. Frequently Asked Questions 1. Explain the concept of Streams 2. Explain the various input output stream classes http://improvejava.blogspot.in/ 22