SlideShare a Scribd company logo
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
Ad

More Related Content

What's hot (20)

MULTI THREADING IN JAVA
MULTI THREADING IN JAVAMULTI THREADING IN JAVA
MULTI THREADING IN JAVA
VINOTH R
 
Method overloading
Method overloadingMethod overloading
Method overloading
Lovely Professional University
 
Java package
Java packageJava package
Java package
CS_GDRCST
 
Data types in java
Data types in javaData types in java
Data types in java
HarshitaAshwani
 
Applets in java
Applets in javaApplets in java
Applets in java
Wani Zahoor
 
Templates in c++
Templates in c++Templates in c++
Templates in c++
ThamizhselviKrishnam
 
Java threads
Java threadsJava threads
Java threads
Prabhakaran V M
 
Java exception handling
Java exception handlingJava exception handling
Java exception handling
BHUVIJAYAVELU
 
Polymorphism in c++(ppt)
Polymorphism in c++(ppt)Polymorphism in c++(ppt)
Polymorphism in c++(ppt)
Sanjit Shaw
 
Java interfaces
Java interfacesJava interfaces
Java interfaces
Raja Sekhar
 
Wrapper class
Wrapper classWrapper class
Wrapper class
kamal kotecha
 
virtual function
virtual functionvirtual function
virtual function
VENNILAV6
 
I/O Streams
I/O StreamsI/O Streams
I/O Streams
Ravi Chythanya
 
java interface and packages
java interface and packagesjava interface and packages
java interface and packages
VINOTH R
 
Data types in python
Data types in pythonData types in python
Data types in python
RaginiJain21
 
Java thread life cycle
Java thread life cycleJava thread life cycle
Java thread life cycle
Archana Gopinath
 
Type casting in java
Type casting in javaType casting in java
Type casting in java
Farooq Baloch
 
Type conversion
Type  conversionType  conversion
Type conversion
PreethaPreetha5
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
Vineeta Garg
 
Passing an Array to a Function (ICT Programming)
Passing an Array to a Function (ICT Programming)Passing an Array to a Function (ICT Programming)
Passing an Array to a Function (ICT Programming)
Fatima Kate Tanay
 

Similar to Java Streams (20)

Io Streams
Io StreamsIo Streams
Io Streams
phanleson
 
Java IO Stream, the introduction to Streams
Java IO Stream, the introduction to StreamsJava IO Stream, the introduction to Streams
Java IO Stream, the introduction to Streams
ranganadh6
 
File Input and output.pptx
File Input  and output.pptxFile Input  and output.pptx
File Input and output.pptx
cherryreddygannu
 
Java stream
Java streamJava stream
Java stream
Arati Gadgil
 
Stream In Java.pptx
Stream In Java.pptxStream In Java.pptx
Stream In Java.pptx
ssuser9d7049
 
Unit IV Notes.docx
Unit IV Notes.docxUnit IV Notes.docx
Unit IV Notes.docx
GayathriRHICETCSESTA
 
Oodp mod4
Oodp mod4Oodp mod4
Oodp mod4
cs19club
 
Io Streams
Io StreamsIo Streams
Io Streams
leminhvuong
 
Itp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & OutputItp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & Output
phanleson
 
Java
JavaJava
Java
Dhruv Sabalpara
 
UNIT4-IO,Generics,String Handling.pdf Notes
UNIT4-IO,Generics,String Handling.pdf NotesUNIT4-IO,Generics,String Handling.pdf Notes
UNIT4-IO,Generics,String Handling.pdf Notes
SakkaravarthiS1
 
Java - File Input Output Concepts
Java - File Input Output ConceptsJava - File Input Output Concepts
Java - File Input Output Concepts
Victer Paul
 
Java Input and Output
Java Input and OutputJava Input and Output
Java Input and Output
Ducat India
 
Md121 streams
Md121 streamsMd121 streams
Md121 streams
Rakesh Madugula
 
Java - Processing input and output
Java - Processing input and outputJava - Processing input and output
Java - Processing input and output
Riccardo Cardin
 
Stream Based Input Output
Stream Based Input OutputStream Based Input Output
Stream Based Input Output
Bharat17485
 
Java program file I/O
Java program file I/OJava program file I/O
Java program file I/O
Nem Sothea
 
Computer science input and output BASICS.pptx
Computer science input and output BASICS.pptxComputer science input and output BASICS.pptx
Computer science input and output BASICS.pptx
RathanMB
 
L21 io streams
L21 io streamsL21 io streams
L21 io streams
teach4uin
 
Io streams
Io streamsIo streams
Io streams
Elizabeth alexander
 
Java IO Stream, the introduction to Streams
Java IO Stream, the introduction to StreamsJava IO Stream, the introduction to Streams
Java IO Stream, the introduction to Streams
ranganadh6
 
File Input and output.pptx
File Input  and output.pptxFile Input  and output.pptx
File Input and output.pptx
cherryreddygannu
 
Stream In Java.pptx
Stream In Java.pptxStream In Java.pptx
Stream In Java.pptx
ssuser9d7049
 
Itp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & OutputItp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & Output
phanleson
 
UNIT4-IO,Generics,String Handling.pdf Notes
UNIT4-IO,Generics,String Handling.pdf NotesUNIT4-IO,Generics,String Handling.pdf Notes
UNIT4-IO,Generics,String Handling.pdf Notes
SakkaravarthiS1
 
Java - File Input Output Concepts
Java - File Input Output ConceptsJava - File Input Output Concepts
Java - File Input Output Concepts
Victer Paul
 
Java Input and Output
Java Input and OutputJava Input and Output
Java Input and Output
Ducat India
 
Java - Processing input and output
Java - Processing input and outputJava - Processing input and output
Java - Processing input and output
Riccardo Cardin
 
Stream Based Input Output
Stream Based Input OutputStream Based Input Output
Stream Based Input Output
Bharat17485
 
Java program file I/O
Java program file I/OJava program file I/O
Java program file I/O
Nem Sothea
 
Computer science input and output BASICS.pptx
Computer science input and output BASICS.pptxComputer science input and output BASICS.pptx
Computer science input and output BASICS.pptx
RathanMB
 
L21 io streams
L21 io streamsL21 io streams
L21 io streams
teach4uin
 
Ad

More from M Vishnuvardhan Reddy (20)

Python Sets_Dictionary.pptx
Python Sets_Dictionary.pptxPython Sets_Dictionary.pptx
Python Sets_Dictionary.pptx
M Vishnuvardhan Reddy
 
Lists_tuples.pptx
Lists_tuples.pptxLists_tuples.pptx
Lists_tuples.pptx
M Vishnuvardhan Reddy
 
Python Control Structures.pptx
Python Control Structures.pptxPython Control Structures.pptx
Python Control Structures.pptx
M Vishnuvardhan Reddy
 
Python Strings.pptx
Python Strings.pptxPython Strings.pptx
Python Strings.pptx
M Vishnuvardhan Reddy
 
Python Basics.pptx
Python Basics.pptxPython Basics.pptx
Python Basics.pptx
M Vishnuvardhan Reddy
 
Python Operators.pptx
Python Operators.pptxPython Operators.pptx
Python Operators.pptx
M Vishnuvardhan Reddy
 
Python Datatypes.pptx
Python Datatypes.pptxPython Datatypes.pptx
Python Datatypes.pptx
M Vishnuvardhan Reddy
 
DataScience.pptx
DataScience.pptxDataScience.pptx
DataScience.pptx
M Vishnuvardhan Reddy
 
Html forms
Html formsHtml forms
Html forms
M Vishnuvardhan Reddy
 
Cascading Style Sheets
Cascading Style SheetsCascading Style Sheets
Cascading Style Sheets
M Vishnuvardhan Reddy
 
Java Threads
Java ThreadsJava Threads
Java Threads
M Vishnuvardhan Reddy
 
Scanner class
Scanner classScanner class
Scanner class
M Vishnuvardhan Reddy
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
M Vishnuvardhan Reddy
 
Java intro
Java introJava intro
Java intro
M Vishnuvardhan Reddy
 
Java applets
Java appletsJava applets
Java applets
M Vishnuvardhan Reddy
 
Exception handling
Exception handling Exception handling
Exception handling
M Vishnuvardhan Reddy
 
Control structures
Control structuresControl structures
Control structures
M Vishnuvardhan Reddy
 
Constructors
ConstructorsConstructors
Constructors
M Vishnuvardhan Reddy
 
Classes&objects
Classes&objectsClasses&objects
Classes&objects
M Vishnuvardhan Reddy
 
Shell sort
Shell sortShell sort
Shell sort
M Vishnuvardhan Reddy
 
Ad

Recently uploaded (20)

Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Dele Amefo
 
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
ssuserb14185
 
Not So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java WebinarNot So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java Webinar
Tier1 app
 
Adobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest VersionAdobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest Version
kashifyounis067
 
Exploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the FutureExploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the Future
ICS
 
EASEUS Partition Master Crack + License Code
EASEUS Partition Master Crack + License CodeEASEUS Partition Master Crack + License Code
EASEUS Partition Master Crack + License Code
aneelaramzan63
 
Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]
saniaaftab72555
 
WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)
sh607827
 
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Orangescrum
 
Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025
mu394968
 
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
steaveroggers
 
Automation Techniques in RPA - UiPath Certificate
Automation Techniques in RPA - UiPath CertificateAutomation Techniques in RPA - UiPath Certificate
Automation Techniques in RPA - UiPath Certificate
VICTOR MAESTRE RAMIREZ
 
Solidworks Crack 2025 latest new + license code
Solidworks Crack 2025 latest new + license codeSolidworks Crack 2025 latest new + license code
Solidworks Crack 2025 latest new + license code
aneelaramzan63
 
Landscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature ReviewLandscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature Review
Hironori Washizaki
 
Adobe Master Collection CC Crack Advance Version 2025
Adobe Master Collection CC Crack Advance Version 2025Adobe Master Collection CC Crack Advance Version 2025
Adobe Master Collection CC Crack Advance Version 2025
kashifyounis067
 
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
Andre Hora
 
Adobe After Effects Crack FREE FRESH version 2025
Adobe After Effects Crack FREE FRESH version 2025Adobe After Effects Crack FREE FRESH version 2025
Adobe After Effects Crack FREE FRESH version 2025
kashifyounis067
 
Meet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Meet the Agents: How AI Is Learning to Think, Plan, and CollaborateMeet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Meet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Maxim Salnikov
 
The Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdfThe Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdf
drewplanas10
 
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
AxisTechnolabs
 
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Dele Amefo
 
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
ssuserb14185
 
Not So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java WebinarNot So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java Webinar
Tier1 app
 
Adobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest VersionAdobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest Version
kashifyounis067
 
Exploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the FutureExploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the Future
ICS
 
EASEUS Partition Master Crack + License Code
EASEUS Partition Master Crack + License CodeEASEUS Partition Master Crack + License Code
EASEUS Partition Master Crack + License Code
aneelaramzan63
 
Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]
saniaaftab72555
 
WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)
sh607827
 
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Orangescrum
 
Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025
mu394968
 
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
steaveroggers
 
Automation Techniques in RPA - UiPath Certificate
Automation Techniques in RPA - UiPath CertificateAutomation Techniques in RPA - UiPath Certificate
Automation Techniques in RPA - UiPath Certificate
VICTOR MAESTRE RAMIREZ
 
Solidworks Crack 2025 latest new + license code
Solidworks Crack 2025 latest new + license codeSolidworks Crack 2025 latest new + license code
Solidworks Crack 2025 latest new + license code
aneelaramzan63
 
Landscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature ReviewLandscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature Review
Hironori Washizaki
 
Adobe Master Collection CC Crack Advance Version 2025
Adobe Master Collection CC Crack Advance Version 2025Adobe Master Collection CC Crack Advance Version 2025
Adobe Master Collection CC Crack Advance Version 2025
kashifyounis067
 
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
Andre Hora
 
Adobe After Effects Crack FREE FRESH version 2025
Adobe After Effects Crack FREE FRESH version 2025Adobe After Effects Crack FREE FRESH version 2025
Adobe After Effects Crack FREE FRESH version 2025
kashifyounis067
 
Meet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Meet the Agents: How AI Is Learning to Think, Plan, and CollaborateMeet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Meet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Maxim Salnikov
 
The Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdfThe Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdf
drewplanas10
 
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
AxisTechnolabs
 

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