SlideShare ist ein Scribd-Unternehmen logo
1 von 23
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

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

Constructor in java
Constructor in javaConstructor in java
Constructor in java
 
Basic concept of OOP's
Basic concept of OOP'sBasic concept of OOP's
Basic concept of OOP's
 
Java package
Java packageJava package
Java package
 
MULTI THREADING IN JAVA
MULTI THREADING IN JAVAMULTI THREADING IN JAVA
MULTI THREADING IN JAVA
 
Wrapper class
Wrapper classWrapper class
Wrapper class
 
Files in java
Files in javaFiles in java
Files in java
 
Java threads
Java threadsJava threads
Java threads
 
Packages in java
Packages in javaPackages in java
Packages in java
 
Threads in JAVA
Threads in JAVAThreads in JAVA
Threads in JAVA
 
Strings in Java
Strings in JavaStrings in Java
Strings in Java
 
String and string buffer
String and string bufferString and string buffer
String and string buffer
 
Java interfaces
Java interfacesJava interfaces
Java interfaces
 
Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVA
 
Exception Handling in Java
Exception Handling in JavaException Handling in Java
Exception Handling in Java
 
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in java
 
Class and Objects in Java
Class and Objects in JavaClass and Objects in Java
Class and Objects in Java
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)
 
Java exception handling
Java exception handlingJava exception handling
Java exception handling
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
 

Ähnlich wie Java Streams

File Input and output.pptx
File Input  and output.pptxFile Input  and output.pptx
File Input and output.pptxcherryreddygannu
 
Stream In Java.pptx
Stream In Java.pptxStream In Java.pptx
Stream In Java.pptxssuser9d7049
 
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 & Outputphanleson
 
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 NotesSakkaravarthiS1
 
Java - File Input Output Concepts
Java - File Input Output ConceptsJava - File Input Output Concepts
Java - File Input Output ConceptsVicter Paul
 
Java Input and Output
Java Input and OutputJava Input and Output
Java Input and OutputDucat India
 
Java - Processing input and output
Java - Processing input and outputJava - Processing input and output
Java - Processing input and outputRiccardo Cardin
 
Stream Based Input Output
Stream Based Input OutputStream Based Input Output
Stream Based Input OutputBharat17485
 
Java program file I/O
Java program file I/OJava program file I/O
Java program file I/ONem 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.pptxRathanMB
 
L21 io streams
L21 io streamsL21 io streams
L21 io streamsteach4uin
 

Ähnlich wie Java Streams (20)

Io Streams
Io StreamsIo Streams
Io Streams
 
File Input and output.pptx
File Input  and output.pptxFile Input  and output.pptx
File Input and output.pptx
 
Java stream
Java streamJava stream
Java stream
 
Stream In Java.pptx
Stream In Java.pptxStream In Java.pptx
Stream In Java.pptx
 
Unit IV Notes.docx
Unit IV Notes.docxUnit IV Notes.docx
Unit IV Notes.docx
 
Oodp mod4
Oodp mod4Oodp mod4
Oodp mod4
 
Io Streams
Io StreamsIo Streams
Io Streams
 
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
 
Java
JavaJava
Java
 
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
 
Java - File Input Output Concepts
Java - File Input Output ConceptsJava - File Input Output Concepts
Java - File Input Output Concepts
 
Java Input and Output
Java Input and OutputJava Input and Output
Java Input and Output
 
Md121 streams
Md121 streamsMd121 streams
Md121 streams
 
Java - Processing input and output
Java - Processing input and outputJava - Processing input and output
Java - Processing input and output
 
Stream Based Input Output
Stream Based Input OutputStream Based Input Output
Stream Based Input Output
 
Java program file I/O
Java program file I/OJava program file I/O
Java program file I/O
 
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
 
I/O Streams
I/O StreamsI/O Streams
I/O Streams
 
L21 io streams
L21 io streamsL21 io streams
L21 io streams
 
Io streams
Io streamsIo streams
Io streams
 

Mehr von M Vishnuvardhan Reddy (20)

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

Kürzlich hochgeladen

5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 

Kürzlich hochgeladen (20)

5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.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