SlideShare a Scribd company logo
2
Most read
3
Most read
4
Most read
Streams
In JAVA
-M Vishnuvardhan,
Dept. of Computer Science,
SSBN Degree College, ATP
SSBN Degree College, ATP M Vishnuvardhan
Introduction
Streams are used to transfer the data between program and
source/destination. They transfer the data in unique way
irrespective of source/destination. Streams are defined in
java.io package in java.
Depending up on the direction of the transfer the streams are
classified in to two categories.
Input Stream:
Output Stream
Program Source 
read()
Program Destination 
write ()
SSBN Degree College, ATP M Vishnuvardhan
Introduction
Depending up on how the streams carry the data, they classified
in to two
Byte Streams
These streams carry the data in the form of bytes. They use 8
bit (1 byte) of storage to read the data
Character Streams
These streams carry the data in the form of characters. They
use 2 bytes storage
SSBN Degree College, ATP M Vishnuvardhan
InputStream methods
Method name Description
int read():
Reads next byte from the stream as
integer and returns -1 if no data is
available in the stream
int read(byte b[])
Reads an array full of bytes from the
stream and returns actual number of
bytes read.
int read(byte b[], int start, int end)
Reads bytes in to array from the specified
start and end position form the stream.
long available()
Returns how many number of bytes yet to
be read in the stream.
SSBN Degree College, ATP M Vishnuvardhan
InputStream methods
Method name Description
long skip(long n)
Skips specified number of bytes in the
input stream and returns actual number of
bytes skipped
void mark(int readLimit)
Marks the current position and it is valid
till specified read limit.
void reset()
Moves to the recent marked position or
beginning of the stream
void close() Closes the stream
SSBN Degree College, ATP M Vishnuvardhan
Byte Input Streams
FileInputStream
PipedInputStream
ByteArrayInputStream StringBufferInputStream
ObjectInputStream
SequenceInputStream
InputStream
FilterInputStream
BufferedInputStream PushBackInputStream
DataInputStream
SSBN Degree College, ATP M Vishnuvardhan
Various Byte Input Streams
Stream Class Name Use
FileInputStream used to read from files
PipedInputStream used to read from pipes
ByteArrayInputStream used to read from a byte array
StringBufferInputStream used to read from a String buffer object
ObjectInputStream used to read objects from an input stream
SequenceInputStream used to combine two or more input streams
BufferedInputStream provides buffer facility to the input stream
DataInputStream used to read primitive data from the input
stream
PushBackInputStream provides un reading facility to the input
stream
SSBN Degree College, ATP M Vishnuvardhan
Byte Output Streams
FileOutputStream
PipedOutputStream ByteArrayOutputStream
ObjectOutputStream
OutputStream
FilterOutputStream
BufferedOutputStream
DataOutputStream
PrintStream
SSBN Degree College, ATP M Vishnuvardhan
OutputStream methods
Method name Description
void write(int b) Writes one byte to output stream
void write(byte b[])
Writes an array full of bytes to output
stream
void write(byte b[], int start, int end)
Writes bytes from array to output
stream from the specified start and end
position
void flush()
Flushes the output stream i.e.,
immediately releases the pending data
from stream
void close()
Closes the output stream
SSBN Degree College, ATP M Vishnuvardhan
Byte Output Streams
Stream Class Name Use
FileOutputStream used to write data into a file
PipedOutputStream used to write data to a pipe
ByteArrayOutputStream used to write data to a byte array
ObjectOutputStream used to write objects to a output stream
BufferedOutputStream provides buffer facility to the output stream
DataOutputStream used to write primitive data to an input
stream
PrintStream Used to print any data on output stream
SSBN Degree College, ATP M Vishnuvardhan
Character Input Streams
FileReader
PipedReader
CharArrayReader
InputStreamReader
StringReader
Reader
FilterReader
BufferedReader
PushBackReader
SSBN Degree College, ATP M Vishnuvardhan
Reader methods
Method name Description
int read():
Reads next character from the stream as
integer and returns -1 if no data is
available in the stream.
int read(char c[])
Reads an array full of characters from the
stream and returns actual number of
characters read
int read(char c[], int start, int end)
Reads characters in to array from the
specified start and end position form the
stream
long available()
Returns how many number of bytes yet to
be read in the stream.
SSBN Degree College, ATP M Vishnuvardhan
Reader methods
Method name Description
long skip(long n)
Skips specified number of bytes in the
input stream and returns actual number of
bytes skipped
void mark(int readLimit)
Marks the current position and it is valid
till specified read limit.
void reset()
Moves to the recent marked position or
beginning of the stream
void close() Closes the stream
SSBN Degree College, ATP M Vishnuvardhan
Character Input Streams
Stream Class Name Use
FileReader used to read from files
PipedReader used to read from pipes
CharArrayReader used to read from a char array
StringReader used to read from a String
InputStreamReader used to convert byte stream to character
stream
BufferedReader provides buffer facility to the Reader
PushBackReader provides un reading facility to the Reader
SSBN Degree College, ATP M Vishnuvardhan
Character Output Streams
FileWriter
PipedWriter
CharArrayWriter
OutputStreamWriter
StringWriter
Writer
FilterWriter
BufferedWriter
PrintWriter
SSBN Degree College, ATP M Vishnuvardhan
Writer methods
Method name Description
void write(int c) Writes one char to output stream
void write(char c[])
Writes an array full of chars to output
stream
void write(char c[], int start, int end)
Writes chars from array to output stream
from the specified start and end position
void flush()
Flushes the output stream i.e.,
immediately releases the pending data
from stream
void close()
Closes the output stream
SSBN Degree College, ATP M Vishnuvardhan
Character Output Streams
Stream Class Name Use
FileWriter used to write data into a file
PipedWriter used to write data to a pipe
CharArrayWriter used to write data to a byte array
StringWriter used to write string to a Writer
PrintWriter used to print any data on Writer
BufferedWriter provides buffer facility to the Writer
OutputStreamWriter used to convert character stream to byte
stream
SSBN Degree College, ATP M Vishnuvardhan
Exceptions
 FileNotFoundException
Raises when an attempt is made to open a file which doesnot
exist physically on the disk
 IOException
 Raises when
SSBN Degree College, ATP M Vishnuvardhan
File class
File is a not a stream class but it is part of java.io package which is
used to provide support for files and directories.
Constructors:
File(String fileName):
Constructs a file object with full path of the file
Eg: File f1=new File (“D:ProgramsJavaFileDemo.java”);
File(String parent, String fileName)
Constructs a file object for the file at specified path
Eg: File f2=new File (“D:ProgramJava”,”FileDemo.java”);
SSBN Degree College, ATP M Vishnuvardhan
File Methods:
 String getName(): Returns the name of the file
 String getPath(): Returns path of the file
 boolean isFile(): Returns true if the file object is
a file otherwise false is returned
 boolean isDirectory(): Returns true if the file
object is a directory
 long length(): Returns the size of the file in bytes
 String list[]: Returns an array of strings
representing the files present in the
directory
SSBN Degree College, ATP M Vishnuvardhan
Reading & writing files
 Reading / Writing Bytes
 FileInputStream
 FileOutputStream
 Reading / Writing Characters
 FileReader
 FileWriter
 Reading / Writing Primitive data types
 DataInputStream
 DataOutputStream
SSBN Degree College, ATP M Vishnuvardhan
Reading & writing files
Using DataInputStream and DataOutputStream
FileInputStream fis=new FileInputStream(“Student.txt”);
DataInputStream dis=new DataInputStream(fis);
FileOutputStream fos=new FileOutputStream(“Student.txt”);
DataOutputStream dos=new DataOutputStream(fos);
FileInputStream
File Program
DataInputStream
FileOutputStream
File Program
DataOutputStream
SSBN Degree College, ATP M Vishnuvardhan
Questions

More Related Content

PDF
Java I/o streams
PPTX
Types of Machine Learning
PPTX
Deep learning.pptx
PDF
Lecture4 big data technology foundations
PPTX
I/O Streams
PPT
Types of Pollution Powerpoint presentation
PDF
PPTX
OOPS Basics With Example
Java I/o streams
Types of Machine Learning
Deep learning.pptx
Lecture4 big data technology foundations
I/O Streams
Types of Pollution Powerpoint presentation
OOPS Basics With Example

What's hot (20)

PPTX
Packages in java
PPTX
JAVA AWT
PPTX
Java package
PPTX
Classes, objects in JAVA
PPTX
Type casting in java
PPTX
Applets in java
PPTX
Inheritance in java
PPTX
Constructor in java
PPTX
Method overloading
PPTX
Control statements in java
PDF
input/ output in java
PPT
Java-java virtual machine
PPTX
Arrays in Java
PPTX
Interface in java
PPTX
Java abstract class & abstract methods
PPTX
6. static keyword
PPTX
File handling in Python
PPTX
Inheritance in java
PPTX
java interface and packages
Packages in java
JAVA AWT
Java package
Classes, objects in JAVA
Type casting in java
Applets in java
Inheritance in java
Constructor in java
Method overloading
Control statements in java
input/ output in java
Java-java virtual machine
Arrays in Java
Interface in java
Java abstract class & abstract methods
6. static keyword
File handling in Python
Inheritance in java
java interface and packages
Ad

Similar to Java Streams (20)

PPT
Io Streams
PDF
Java IO Stream, the introduction to Streams
PPTX
File Input and output.pptx
PPT
Java stream
PPTX
Stream In Java.pptx
DOCX
Unit IV Notes.docx
DOCX
Oodp mod4
PPT
Io Streams
PPT
Itp 120 Chapt 19 2009 Binary Input & Output
PPTX
PDF
UNIT4-IO,Generics,String Handling.pdf Notes
PDF
Java - File Input Output Concepts
PPTX
Java Input and Output
PPT
Md121 streams
PPTX
Java - Processing input and output
PPT
Stream Based Input Output
PPTX
Java program file I/O
PPTX
Computer science input and output BASICS.pptx
PPTX
L21 io streams
PPTX
Io Streams
Java IO Stream, the introduction to Streams
File Input and output.pptx
Java stream
Stream In Java.pptx
Unit IV Notes.docx
Oodp mod4
Io Streams
Itp 120 Chapt 19 2009 Binary Input & Output
UNIT4-IO,Generics,String Handling.pdf Notes
Java - File Input Output Concepts
Java Input and Output
Md121 streams
Java - Processing input and output
Stream Based Input Output
Java program file I/O
Computer science input and output BASICS.pptx
L21 io streams
Ad

More from M Vishnuvardhan Reddy (20)

PPTX
Python Sets_Dictionary.pptx
PPTX
Lists_tuples.pptx
PPTX
Python Control Structures.pptx
PPTX
Python Strings.pptx
PPTX
Python Basics.pptx
PPTX
Python Operators.pptx
PPTX
Python Datatypes.pptx
PPTX
DataScience.pptx
PPT
PPT
Cascading Style Sheets
PPT
Java Threads
PPT
Scanner class
PPT
Polymorphism
PPT
PPT
Java applets
PPT
Exception handling
PPT
Control structures
PPT
Constructors
PPT
Classes&objects
PPS
Python Sets_Dictionary.pptx
Lists_tuples.pptx
Python Control Structures.pptx
Python Strings.pptx
Python Basics.pptx
Python Operators.pptx
Python Datatypes.pptx
DataScience.pptx
Cascading Style Sheets
Java Threads
Scanner class
Polymorphism
Java applets
Exception handling
Control structures
Constructors
Classes&objects

Recently uploaded (20)

DOCX
The Five Best AI Cover Tools in 2025.docx
PDF
Become an Agentblazer Champion Challenge Kickoff
PDF
Jenkins: An open-source automation server powering CI/CD Automation
PDF
Emergency Mustering solutions – A Brief overview
PPTX
Presentation of Computer CLASS 2 .pptx
PDF
Multi-factor Authentication (MFA) requirement for Microsoft 365 Admin Center_...
DOCX
The Future of Smart Factories Why Embedded Analytics Leads the Way
PDF
IEEE-CS Tech Predictions, SWEBOK and Quantum Software: Towards Q-SWEBOK
PPTX
Materi_Pemrograman_Komputer-Looping.pptx
PDF
Exploring AI Agents in Process Industries
PPTX
Materi-Enum-and-Record-Data-Type (1).pptx
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
How Creative Agencies Leverage Project Management Software.pdf
PPTX
Dynamic Solutions Project Pitch Presentation
PPTX
Save Business Costs with CRM Software for Insurance Agents
PDF
A REACT POMODORO TIMER WEB APPLICATION.pdf
PDF
Comprehensive Salesforce Implementation Services.pdf
PPTX
Odoo Consulting Services by CandidRoot Solutions
PPTX
Visualising Data with Scatterplots in IBM SPSS Statistics.pptx
PDF
How to Seamlessly Integrate Salesforce Data Cloud with Marketing Cloud.pdf
The Five Best AI Cover Tools in 2025.docx
Become an Agentblazer Champion Challenge Kickoff
Jenkins: An open-source automation server powering CI/CD Automation
Emergency Mustering solutions – A Brief overview
Presentation of Computer CLASS 2 .pptx
Multi-factor Authentication (MFA) requirement for Microsoft 365 Admin Center_...
The Future of Smart Factories Why Embedded Analytics Leads the Way
IEEE-CS Tech Predictions, SWEBOK and Quantum Software: Towards Q-SWEBOK
Materi_Pemrograman_Komputer-Looping.pptx
Exploring AI Agents in Process Industries
Materi-Enum-and-Record-Data-Type (1).pptx
PTS Company Brochure 2025 (1).pdf.......
How Creative Agencies Leverage Project Management Software.pdf
Dynamic Solutions Project Pitch Presentation
Save Business Costs with CRM Software for Insurance Agents
A REACT POMODORO TIMER WEB APPLICATION.pdf
Comprehensive Salesforce Implementation Services.pdf
Odoo Consulting Services by CandidRoot Solutions
Visualising Data with Scatterplots in IBM SPSS Statistics.pptx
How to Seamlessly Integrate Salesforce Data Cloud with Marketing Cloud.pdf

Java Streams

  • 1. Streams In JAVA -M Vishnuvardhan, Dept. of Computer Science, SSBN Degree College, ATP
  • 2. SSBN Degree College, ATP M Vishnuvardhan Introduction Streams are used to transfer the data between program and source/destination. They transfer the data in unique way irrespective of source/destination. Streams are defined in java.io package in java. Depending up on the direction of the transfer the streams are classified in to two categories. Input Stream: Output Stream Program Source  read() Program Destination  write ()
  • 3. SSBN Degree College, ATP M Vishnuvardhan Introduction Depending up on how the streams carry the data, they classified in to two Byte Streams These streams carry the data in the form of bytes. They use 8 bit (1 byte) of storage to read the data Character Streams These streams carry the data in the form of characters. They use 2 bytes storage
  • 4. SSBN Degree College, ATP M Vishnuvardhan InputStream methods Method name Description int read(): Reads next byte from the stream as integer and returns -1 if no data is available in the stream int read(byte b[]) Reads an array full of bytes from the stream and returns actual number of bytes read. int read(byte b[], int start, int end) Reads bytes in to array from the specified start and end position form the stream. long available() Returns how many number of bytes yet to be read in the stream.
  • 5. SSBN Degree College, ATP M Vishnuvardhan InputStream methods Method name Description long skip(long n) Skips specified number of bytes in the input stream and returns actual number of bytes skipped void mark(int readLimit) Marks the current position and it is valid till specified read limit. void reset() Moves to the recent marked position or beginning of the stream void close() Closes the stream
  • 6. SSBN Degree College, ATP M Vishnuvardhan Byte Input Streams FileInputStream PipedInputStream ByteArrayInputStream StringBufferInputStream ObjectInputStream SequenceInputStream InputStream FilterInputStream BufferedInputStream PushBackInputStream DataInputStream
  • 7. SSBN Degree College, ATP M Vishnuvardhan Various Byte Input Streams Stream Class Name Use FileInputStream used to read from files PipedInputStream used to read from pipes ByteArrayInputStream used to read from a byte array StringBufferInputStream used to read from a String buffer object ObjectInputStream used to read objects from an input stream SequenceInputStream used to combine two or more input streams BufferedInputStream provides buffer facility to the input stream DataInputStream used to read primitive data from the input stream PushBackInputStream provides un reading facility to the input stream
  • 8. SSBN Degree College, ATP M Vishnuvardhan Byte Output Streams FileOutputStream PipedOutputStream ByteArrayOutputStream ObjectOutputStream OutputStream FilterOutputStream BufferedOutputStream DataOutputStream PrintStream
  • 9. SSBN Degree College, ATP M Vishnuvardhan OutputStream methods Method name Description void write(int b) Writes one byte to output stream void write(byte b[]) Writes an array full of bytes to output stream void write(byte b[], int start, int end) Writes bytes from array to output stream from the specified start and end position void flush() Flushes the output stream i.e., immediately releases the pending data from stream void close() Closes the output stream
  • 10. SSBN Degree College, ATP M Vishnuvardhan Byte Output Streams Stream Class Name Use FileOutputStream used to write data into a file PipedOutputStream used to write data to a pipe ByteArrayOutputStream used to write data to a byte array ObjectOutputStream used to write objects to a output stream BufferedOutputStream provides buffer facility to the output stream DataOutputStream used to write primitive data to an input stream PrintStream Used to print any data on output stream
  • 11. SSBN Degree College, ATP M Vishnuvardhan Character Input Streams FileReader PipedReader CharArrayReader InputStreamReader StringReader Reader FilterReader BufferedReader PushBackReader
  • 12. SSBN Degree College, ATP M Vishnuvardhan Reader methods Method name Description int read(): Reads next character from the stream as integer and returns -1 if no data is available in the stream. int read(char c[]) Reads an array full of characters from the stream and returns actual number of characters read int read(char c[], int start, int end) Reads characters in to array from the specified start and end position form the stream long available() Returns how many number of bytes yet to be read in the stream.
  • 13. SSBN Degree College, ATP M Vishnuvardhan Reader methods Method name Description long skip(long n) Skips specified number of bytes in the input stream and returns actual number of bytes skipped void mark(int readLimit) Marks the current position and it is valid till specified read limit. void reset() Moves to the recent marked position or beginning of the stream void close() Closes the stream
  • 14. SSBN Degree College, ATP M Vishnuvardhan Character Input Streams Stream Class Name Use FileReader used to read from files PipedReader used to read from pipes CharArrayReader used to read from a char array StringReader used to read from a String InputStreamReader used to convert byte stream to character stream BufferedReader provides buffer facility to the Reader PushBackReader provides un reading facility to the Reader
  • 15. SSBN Degree College, ATP M Vishnuvardhan Character Output Streams FileWriter PipedWriter CharArrayWriter OutputStreamWriter StringWriter Writer FilterWriter BufferedWriter PrintWriter
  • 16. SSBN Degree College, ATP M Vishnuvardhan Writer methods Method name Description void write(int c) Writes one char to output stream void write(char c[]) Writes an array full of chars to output stream void write(char c[], int start, int end) Writes chars from array to output stream from the specified start and end position void flush() Flushes the output stream i.e., immediately releases the pending data from stream void close() Closes the output stream
  • 17. SSBN Degree College, ATP M Vishnuvardhan Character Output Streams Stream Class Name Use FileWriter used to write data into a file PipedWriter used to write data to a pipe CharArrayWriter used to write data to a byte array StringWriter used to write string to a Writer PrintWriter used to print any data on Writer BufferedWriter provides buffer facility to the Writer OutputStreamWriter used to convert character stream to byte stream
  • 18. SSBN Degree College, ATP M Vishnuvardhan Exceptions  FileNotFoundException Raises when an attempt is made to open a file which doesnot exist physically on the disk  IOException  Raises when
  • 19. SSBN Degree College, ATP M Vishnuvardhan File class File is a not a stream class but it is part of java.io package which is used to provide support for files and directories. Constructors: File(String fileName): Constructs a file object with full path of the file Eg: File f1=new File (“D:ProgramsJavaFileDemo.java”); File(String parent, String fileName) Constructs a file object for the file at specified path Eg: File f2=new File (“D:ProgramJava”,”FileDemo.java”);
  • 20. SSBN Degree College, ATP M Vishnuvardhan File Methods:  String getName(): Returns the name of the file  String getPath(): Returns path of the file  boolean isFile(): Returns true if the file object is a file otherwise false is returned  boolean isDirectory(): Returns true if the file object is a directory  long length(): Returns the size of the file in bytes  String list[]: Returns an array of strings representing the files present in the directory
  • 21. SSBN Degree College, ATP M Vishnuvardhan Reading & writing files  Reading / Writing Bytes  FileInputStream  FileOutputStream  Reading / Writing Characters  FileReader  FileWriter  Reading / Writing Primitive data types  DataInputStream  DataOutputStream
  • 22. SSBN Degree College, ATP M Vishnuvardhan Reading & writing files Using DataInputStream and DataOutputStream FileInputStream fis=new FileInputStream(“Student.txt”); DataInputStream dis=new DataInputStream(fis); FileOutputStream fos=new FileOutputStream(“Student.txt”); DataOutputStream dos=new DataOutputStream(fos); FileInputStream File Program DataInputStream FileOutputStream File Program DataOutputStream
  • 23. SSBN Degree College, ATP M Vishnuvardhan Questions