SlideShare a Scribd company logo
JAVA
I/O Streams
Prepared by
Miss. Arati A. Gadgil
2
I/O Streams
An I/O Stream represents an input source or an output destination. A
stream can represent many different kinds of sources and destinations,
including disk files, devices, other programs, and memory arrays.
Streams support many different kinds of data, including simple bytes,
primitive data types, localized characters, and objects. Some streams
simply pass on data; others manipulate and transform the data in useful
ways.
A stream is a sequence of data.
A program uses an input stream to read data from a source, one item at a
time.
A program uses an output stream to write data to a destination, one item
at time
3
The basic stream classes are defined in the package “java.io”.
A Java program is reasonably well served by its default state when
execution begins. Three streams are setup and ready to go. There are two
output streams, identified by the objects System.out and System.err, and
one input stream, identified by the object System.in. These objects are
defined as public data fields in the System class of the java.lang package
The err and out objects are instances of the PrintStream class and the
in object is an instance of the InputStream class.
Java defines two types of streams.
Byte Stream : It provides a convenient means for handling input and
output of byte.
Character Stream : It provides a convenient means for handling input
and output of characters. Character stream uses Unicode and therefore
can be internationalized.
4
5
Byte Stream Classes
Byte stream is defined by using two abstract class at the top of hierarchy,
they are InputStream and OutputStream
BufferedInputStream :Used for Buffered Input Stream.
BufferedOutputStream: Used for Buffered Output Stream.
DataInputStream: Contains method for reading java standard datatype
DataOutputStream: An output stream that contain method for writing
java standard data type
6
FileInputStreamInput: stream that reads from a file
FileOutputStreamOutput: stream that write to a file.
InputStream: Abstract class that describe stream input.
OutputStream: Abstract class that describe stream output.
PrintStreamOutput: Stream that contain print() and println() method
Methods
read() : reads byte of data.
write() : Writes byte of data.
7
Character Stream Classes
Character stream is also defined by using two abstract class at the top of
hierarchy, they are Reader and Writer.
Charcter stream classes
BufferedReaderHandles buffered input stream.
BufferedWriterHandles buffered output stream.
FileReaderInput stream that reads from file.
FileWriterOutput stream that writes to file.
InputStreamReaderInput stream that translate byte to character
8
OutputStreamReaderOutput stream that translate character to byte.
PrintWriterOutput Stream that contain print() and println() method.
ReaderAbstract class that define character stream input
WriterAbstract class that define character stream output
9
We use the object of BufferedReader class to take inputs from the
keyboard.
read() method is used with BufferedReader object to read characters. As
this function returns integer type value has we need to use typecasting to
convert it into char type.
To read string we have to use readLine() function with BufferedReader
class's object.
10
Scanner
constructors
Scanner(File source)
Constructs a new Scanner that produces values scanned from
the specified file.
Scanner(InputStream source)
Constructs a new Scanner that produces values scanned from
the specified input stream.
Scanner(Readable source)
Constructs a new Scanner that produces values scanned from
the specified source.
Scanner(String source)
Constructs a new Scanner that produces values scanned from
the specified string.
11
Scanner will read a line of input from its source
Scanner sc = new Scanner (System.in);
int i = sc.nextInt();
System.out.println("You entered" + i);
This example reads a single int from System.in and outputs it to
System.out. It does not check that the user actually entered an int.
12
Next Methods
String next() Finds and returns the next complete token from this
scanner.
boolean nextBoolean() Scans the next token of the input into a boolean
value and returns that value.
byte nextByte() Scans the next token of the input as a byte.
double nextDouble() Scans the next token of the input as a double.
float nextFloat() Scans the next token of the input as a float.
int nextInt() Scans the next token of the input as an int.
String nextLine() Advances this scanner past the current line and returns
the input that was skipped.
long nextLong() Scans the next token of the input as a long.
short nextShort() Scans the next token of the input as a short.
13
hasNext methods
boolean hasNext()
Returns true if this scanner has another token in its input.
boolean hasNextBoolean()
Returns true if the next token in this scanner's input can be interpreted as
a boolean value using a case insensitive pattern created from the string
"true|false".
boolean hasNextByte()
Returns true if the next token in this scanner's input can be interpreted as
a byte value in the default radix using the nextByte() method.
boolean hasNextDouble()
Returns true if the next token in this scanner's input can be interpreted as
a double value using the nextDouble() method.
boolean hasNextFloat()
Returns true if the next token in this scanner's input can be interpreted as
a float value using the nextFloat() method.
14
boolean hasNextInt()
Returns true if the next token in this scanner's input can be
interpreted as an int value in the default radix using the nextInt()
method.
boolean hasNextLine()
Returns true if there is another line in the input of this scanner.
boolean hasNextLong()
Returns true if the next token in this scanner's input can be
interpreted as a long value in the default radix using the
nextLong() method.
boolean hasNextShort()
Returns true if the next token in this scanner's input can be
interpreted as a short value in the default radix using the
nextShort() method.
15
RandomAccessFile
The RandomAccessFile class in the Java IO API allows you to move
around a file and read from it or write to it. We can replace existing parts
of a file too. This is not possible with the FileInputStream or
FileOutputStream.
RandomAccessFile file = new
RandomAccessFile("c:datafile.txt", "rw");
To read or write at a specific location in a RandomAccessFile you must
first position the file pointer at the location to read or write. This is done
using the seek() method. The current position of the file pointer can be
obtained by calling the getFilePointer() method.
RandomAccessFile file = new
RandomAccessFile("c:datafile.txt", "rw");
file.seek(200);
long pointer = file.getFilePointer(); file.close();
16
Reading from a RandomAccessFile
Reading from a RandomAccessFile is done using one of it many read()
methods.
RandomAccessFile file = new
RandomAccessFile("c:datafile.txt", "rw");
int aByte = file.read();
file.close();
The read() method reads the byte located a the position in the file
currently pointed to by the file pointer in theRandomAccessFile instance.
17
Writing to a RandomAccessFile
Writing to a RandomAccessFile can be done using one it its
many write() methods.
RandomAccessFile file = new
RandomAccessFile("c:datafile.txt", "rw");
file.write("Hello World".getBytes());
file.close();
Just like with the read() method the write() method advances the file
pointer after being called. That way you don't have to constantly move
the file pointer to write data to a new location in the file.
Thank You
18
Ad

More Related Content

What's hot (20)

Handling I/O in Java
Handling I/O in JavaHandling I/O in Java
Handling I/O in Java
Hiranya Jayathilaka
 
Input output streams
Input output streamsInput output streams
Input output streams
Parthipan Parthi
 
Java - File Input Output Concepts
Java - File Input Output ConceptsJava - File Input Output Concepts
Java - File Input Output Concepts
Victer Paul
 
Files & IO in Java
Files & IO in JavaFiles & IO in Java
Files & IO in Java
CIB Egypt
 
Java I/O
Java I/OJava I/O
Java I/O
Jussi Pohjolainen
 
32.java input-output
32.java input-output32.java input-output
32.java input-output
santosh mishra
 
Java IO Package and Streams
Java IO Package and StreamsJava IO Package and Streams
Java IO Package and Streams
babak danyal
 
Files in java
Files in javaFiles in java
Files in java
Muthukumaran Subramanian
 
java.io - streams and files
java.io - streams and filesjava.io - streams and files
java.io - streams and files
Marcello Thiry
 
Byte stream classes.49
Byte stream classes.49Byte stream classes.49
Byte stream classes.49
myrajendra
 
Chapter 12 - File Input and Output
Chapter 12 - File Input and OutputChapter 12 - File Input and Output
Chapter 12 - File Input and Output
Eduardo Bergavera
 
Various io stream classes .47
Various io stream classes .47Various io stream classes .47
Various io stream classes .47
myrajendra
 
Java file
Java fileJava file
Java file
sonnetdp
 
Javaiostream
JavaiostreamJavaiostream
Javaiostream
Tien Nguyen
 
input/ output in java
input/ output  in javainput/ output  in java
input/ output in java
sharma230399
 
Character stream classes introd .51
Character stream classes introd  .51Character stream classes introd  .51
Character stream classes introd .51
myrajendra
 
IO and serialization
IO and serializationIO and serialization
IO and serialization
backdoor
 
Io streams
Io streamsIo streams
Io streams
Elizabeth alexander
 
Java I/O
Java I/OJava I/O
Java I/O
Jayant Dalvi
 
File Input & Output
File Input & OutputFile Input & Output
File Input & Output
PRN USM
 
Java - File Input Output Concepts
Java - File Input Output ConceptsJava - File Input Output Concepts
Java - File Input Output Concepts
Victer Paul
 
Files & IO in Java
Files & IO in JavaFiles & IO in Java
Files & IO in Java
CIB Egypt
 
Java IO Package and Streams
Java IO Package and StreamsJava IO Package and Streams
Java IO Package and Streams
babak danyal
 
java.io - streams and files
java.io - streams and filesjava.io - streams and files
java.io - streams and files
Marcello Thiry
 
Byte stream classes.49
Byte stream classes.49Byte stream classes.49
Byte stream classes.49
myrajendra
 
Chapter 12 - File Input and Output
Chapter 12 - File Input and OutputChapter 12 - File Input and Output
Chapter 12 - File Input and Output
Eduardo Bergavera
 
Various io stream classes .47
Various io stream classes .47Various io stream classes .47
Various io stream classes .47
myrajendra
 
input/ output in java
input/ output  in javainput/ output  in java
input/ output in java
sharma230399
 
Character stream classes introd .51
Character stream classes introd  .51Character stream classes introd  .51
Character stream classes introd .51
myrajendra
 
IO and serialization
IO and serializationIO and serialization
IO and serialization
backdoor
 
File Input & Output
File Input & OutputFile Input & Output
File Input & Output
PRN USM
 

Similar to Java stream (20)

Oodp mod4
Oodp mod4Oodp mod4
Oodp mod4
cs19club
 
File Input and output.pptx
File Input  and output.pptxFile Input  and output.pptx
File Input and output.pptx
cherryreddygannu
 
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
 
Stream Based Input Output
Stream Based Input OutputStream Based Input Output
Stream Based Input Output
Bharat17485
 
Unit IV Notes.docx
Unit IV Notes.docxUnit IV Notes.docx
Unit IV Notes.docx
GayathriRHICETCSESTA
 
Stream In Java.pptx
Stream In Java.pptxStream In Java.pptx
Stream In Java.pptx
ssuser9d7049
 
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
 
ppt on scanner class
ppt on scanner classppt on scanner class
ppt on scanner class
deepsxn
 
I/O Streams
I/O StreamsI/O Streams
I/O Streams
Ravi Chythanya
 
Java Input and Output
Java Input and OutputJava Input and Output
Java Input and Output
Ducat India
 
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
 
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
 
Io Streams
Io StreamsIo Streams
Io Streams
phanleson
 
Java development development Files lectur6.ppt
Java development development Files lectur6.pptJava development development Files lectur6.ppt
Java development development Files lectur6.ppt
rafeakrafeak
 
File Handling in Java.pdf
File Handling in Java.pdfFile Handling in Java.pdf
File Handling in Java.pdf
SudhanshiBakre1
 
Java Tutorial Lab 6
Java Tutorial Lab 6Java Tutorial Lab 6
Java Tutorial Lab 6
Berk Soysal
 
Web Technology Web Technology Notes Streams Network Principles and SocketsUni...
Web Technology Web Technology Notes Streams Network Principles and SocketsUni...Web Technology Web Technology Notes Streams Network Principles and SocketsUni...
Web Technology Web Technology Notes Streams Network Principles and SocketsUni...
uthayashangar1
 
Buffer and scanner
Buffer and scannerBuffer and scanner
Buffer and scanner
Arif Ullah
 
Class notes(week 5) on command line arguments
Class notes(week 5) on command line argumentsClass notes(week 5) on command line arguments
Class notes(week 5) on command line arguments
Kuntal Bhowmick
 
Nhap xuat trong java
Nhap xuat trong javaNhap xuat trong java
Nhap xuat trong java
tuhn
 
File Input and output.pptx
File Input  and output.pptxFile Input  and output.pptx
File Input and output.pptx
cherryreddygannu
 
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
 
Stream Based Input Output
Stream Based Input OutputStream Based Input Output
Stream Based Input Output
Bharat17485
 
Stream In Java.pptx
Stream In Java.pptxStream In Java.pptx
Stream In Java.pptx
ssuser9d7049
 
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
 
ppt on scanner class
ppt on scanner classppt on scanner class
ppt on scanner class
deepsxn
 
Java Input and Output
Java Input and OutputJava Input and Output
Java Input and Output
Ducat India
 
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
 
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
 
Java development development Files lectur6.ppt
Java development development Files lectur6.pptJava development development Files lectur6.ppt
Java development development Files lectur6.ppt
rafeakrafeak
 
File Handling in Java.pdf
File Handling in Java.pdfFile Handling in Java.pdf
File Handling in Java.pdf
SudhanshiBakre1
 
Java Tutorial Lab 6
Java Tutorial Lab 6Java Tutorial Lab 6
Java Tutorial Lab 6
Berk Soysal
 
Web Technology Web Technology Notes Streams Network Principles and SocketsUni...
Web Technology Web Technology Notes Streams Network Principles and SocketsUni...Web Technology Web Technology Notes Streams Network Principles and SocketsUni...
Web Technology Web Technology Notes Streams Network Principles and SocketsUni...
uthayashangar1
 
Buffer and scanner
Buffer and scannerBuffer and scanner
Buffer and scanner
Arif Ullah
 
Class notes(week 5) on command line arguments
Class notes(week 5) on command line argumentsClass notes(week 5) on command line arguments
Class notes(week 5) on command line arguments
Kuntal Bhowmick
 
Nhap xuat trong java
Nhap xuat trong javaNhap xuat trong java
Nhap xuat trong java
tuhn
 
Ad

More from Arati Gadgil (16)

Java adapter
Java adapterJava adapter
Java adapter
Arati Gadgil
 
Java swing
Java swingJava swing
Java swing
Arati Gadgil
 
Java applet
Java appletJava applet
Java applet
Arati Gadgil
 
Java layoutmanager
Java layoutmanagerJava layoutmanager
Java layoutmanager
Arati Gadgil
 
Java awt
Java awtJava awt
Java awt
Arati Gadgil
 
Java thread
Java threadJava thread
Java thread
Arati Gadgil
 
Java networking
Java networkingJava networking
Java networking
Arati Gadgil
 
Java jdbc
Java jdbcJava jdbc
Java jdbc
Arati Gadgil
 
Java package
Java packageJava package
Java package
Arati Gadgil
 
Java interface
Java interfaceJava interface
Java interface
Arati Gadgil
 
Java inheritance
Java inheritanceJava inheritance
Java inheritance
Arati Gadgil
 
Java eventhandling
Java eventhandlingJava eventhandling
Java eventhandling
Arati Gadgil
 
Java exception
Java exception Java exception
Java exception
Arati Gadgil
 
Java collection
Java collectionJava collection
Java collection
Arati Gadgil
 
Java class
Java classJava class
Java class
Arati Gadgil
 
Java basic
Java basicJava basic
Java basic
Arati Gadgil
 
Ad

Recently uploaded (20)

E-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26ASE-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26AS
Abinash Palangdar
 
How to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 PurchaseHow to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 Purchase
Celine George
 
Overview Well-Being and Creative Careers
Overview Well-Being and Creative CareersOverview Well-Being and Creative Careers
Overview Well-Being and Creative Careers
University of Amsterdam
 
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptxTERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
PoojaSen20
 
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
Dr. Nasir Mustafa
 
Myopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduateMyopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduate
Mohamed Rizk Khodair
 
How to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo SlidesHow to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo Slides
Celine George
 
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptxU3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
Mayuri Chavan
 
Form View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo SlidesForm View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo Slides
Celine George
 
Final Evaluation.docx...........................
Final Evaluation.docx...........................Final Evaluation.docx...........................
Final Evaluation.docx...........................
l1bbyburrell
 
*"Sensing the World: Insect Sensory Systems"*
*"Sensing the World: Insect Sensory Systems"**"Sensing the World: Insect Sensory Systems"*
*"Sensing the World: Insect Sensory Systems"*
Arshad Shaikh
 
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon DolabaniHistory Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
fruinkamel7m
 
Ancient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian HistoryAncient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian History
Virag Sontakke
 
Chemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptxChemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptx
Mayuri Chavan
 
CNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscessCNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscess
Mohamed Rizk Khodair
 
Ajanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of HistoryAjanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of History
Virag Sontakke
 
Botany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic ExcellenceBotany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic Excellence
online college homework help
 
All About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdfAll About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdf
TechSoup
 
APGAR SCORE BY sweety Tamanna Mahapatra MSc Pediatric
APGAR SCORE  BY sweety Tamanna Mahapatra MSc PediatricAPGAR SCORE  BY sweety Tamanna Mahapatra MSc Pediatric
APGAR SCORE BY sweety Tamanna Mahapatra MSc Pediatric
SweetytamannaMohapat
 
2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx
mansk2
 
E-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26ASE-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26AS
Abinash Palangdar
 
How to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 PurchaseHow to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 Purchase
Celine George
 
Overview Well-Being and Creative Careers
Overview Well-Being and Creative CareersOverview Well-Being and Creative Careers
Overview Well-Being and Creative Careers
University of Amsterdam
 
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptxTERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
PoojaSen20
 
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
Dr. Nasir Mustafa
 
Myopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduateMyopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduate
Mohamed Rizk Khodair
 
How to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo SlidesHow to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo Slides
Celine George
 
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptxU3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
Mayuri Chavan
 
Form View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo SlidesForm View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo Slides
Celine George
 
Final Evaluation.docx...........................
Final Evaluation.docx...........................Final Evaluation.docx...........................
Final Evaluation.docx...........................
l1bbyburrell
 
*"Sensing the World: Insect Sensory Systems"*
*"Sensing the World: Insect Sensory Systems"**"Sensing the World: Insect Sensory Systems"*
*"Sensing the World: Insect Sensory Systems"*
Arshad Shaikh
 
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon DolabaniHistory Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
fruinkamel7m
 
Ancient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian HistoryAncient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian History
Virag Sontakke
 
Chemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptxChemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptx
Mayuri Chavan
 
CNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscessCNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscess
Mohamed Rizk Khodair
 
Ajanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of HistoryAjanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of History
Virag Sontakke
 
Botany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic ExcellenceBotany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic Excellence
online college homework help
 
All About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdfAll About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdf
TechSoup
 
APGAR SCORE BY sweety Tamanna Mahapatra MSc Pediatric
APGAR SCORE  BY sweety Tamanna Mahapatra MSc PediatricAPGAR SCORE  BY sweety Tamanna Mahapatra MSc Pediatric
APGAR SCORE BY sweety Tamanna Mahapatra MSc Pediatric
SweetytamannaMohapat
 
2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx
mansk2
 

Java stream

  • 2. 2 I/O Streams An I/O Stream represents an input source or an output destination. A stream can represent many different kinds of sources and destinations, including disk files, devices, other programs, and memory arrays. Streams support many different kinds of data, including simple bytes, primitive data types, localized characters, and objects. Some streams simply pass on data; others manipulate and transform the data in useful ways. A stream is a sequence of data. A program uses an input stream to read data from a source, one item at a time. A program uses an output stream to write data to a destination, one item at time
  • 3. 3 The basic stream classes are defined in the package “java.io”. A Java program is reasonably well served by its default state when execution begins. Three streams are setup and ready to go. There are two output streams, identified by the objects System.out and System.err, and one input stream, identified by the object System.in. These objects are defined as public data fields in the System class of the java.lang package The err and out objects are instances of the PrintStream class and the in object is an instance of the InputStream class. Java defines two types of streams. Byte Stream : It provides a convenient means for handling input and output of byte. Character Stream : It provides a convenient means for handling input and output of characters. Character stream uses Unicode and therefore can be internationalized.
  • 4. 4
  • 5. 5 Byte Stream Classes Byte stream is defined by using two abstract class at the top of hierarchy, they are InputStream and OutputStream BufferedInputStream :Used for Buffered Input Stream. BufferedOutputStream: Used for Buffered Output Stream. DataInputStream: Contains method for reading java standard datatype DataOutputStream: An output stream that contain method for writing java standard data type
  • 6. 6 FileInputStreamInput: stream that reads from a file FileOutputStreamOutput: stream that write to a file. InputStream: Abstract class that describe stream input. OutputStream: Abstract class that describe stream output. PrintStreamOutput: Stream that contain print() and println() method Methods read() : reads byte of data. write() : Writes byte of data.
  • 7. 7 Character Stream Classes Character stream is also defined by using two abstract class at the top of hierarchy, they are Reader and Writer. Charcter stream classes BufferedReaderHandles buffered input stream. BufferedWriterHandles buffered output stream. FileReaderInput stream that reads from file. FileWriterOutput stream that writes to file. InputStreamReaderInput stream that translate byte to character
  • 8. 8 OutputStreamReaderOutput stream that translate character to byte. PrintWriterOutput Stream that contain print() and println() method. ReaderAbstract class that define character stream input WriterAbstract class that define character stream output
  • 9. 9 We use the object of BufferedReader class to take inputs from the keyboard. read() method is used with BufferedReader object to read characters. As this function returns integer type value has we need to use typecasting to convert it into char type. To read string we have to use readLine() function with BufferedReader class's object.
  • 10. 10 Scanner constructors Scanner(File source) Constructs a new Scanner that produces values scanned from the specified file. Scanner(InputStream source) Constructs a new Scanner that produces values scanned from the specified input stream. Scanner(Readable source) Constructs a new Scanner that produces values scanned from the specified source. Scanner(String source) Constructs a new Scanner that produces values scanned from the specified string.
  • 11. 11 Scanner will read a line of input from its source Scanner sc = new Scanner (System.in); int i = sc.nextInt(); System.out.println("You entered" + i); This example reads a single int from System.in and outputs it to System.out. It does not check that the user actually entered an int.
  • 12. 12 Next Methods String next() Finds and returns the next complete token from this scanner. boolean nextBoolean() Scans the next token of the input into a boolean value and returns that value. byte nextByte() Scans the next token of the input as a byte. double nextDouble() Scans the next token of the input as a double. float nextFloat() Scans the next token of the input as a float. int nextInt() Scans the next token of the input as an int. String nextLine() Advances this scanner past the current line and returns the input that was skipped. long nextLong() Scans the next token of the input as a long. short nextShort() Scans the next token of the input as a short.
  • 13. 13 hasNext methods boolean hasNext() Returns true if this scanner has another token in its input. boolean hasNextBoolean() Returns true if the next token in this scanner's input can be interpreted as a boolean value using a case insensitive pattern created from the string "true|false". boolean hasNextByte() Returns true if the next token in this scanner's input can be interpreted as a byte value in the default radix using the nextByte() method. boolean hasNextDouble() Returns true if the next token in this scanner's input can be interpreted as a double value using the nextDouble() method. boolean hasNextFloat() Returns true if the next token in this scanner's input can be interpreted as a float value using the nextFloat() method.
  • 14. 14 boolean hasNextInt() Returns true if the next token in this scanner's input can be interpreted as an int value in the default radix using the nextInt() method. boolean hasNextLine() Returns true if there is another line in the input of this scanner. boolean hasNextLong() Returns true if the next token in this scanner's input can be interpreted as a long value in the default radix using the nextLong() method. boolean hasNextShort() Returns true if the next token in this scanner's input can be interpreted as a short value in the default radix using the nextShort() method.
  • 15. 15 RandomAccessFile The RandomAccessFile class in the Java IO API allows you to move around a file and read from it or write to it. We can replace existing parts of a file too. This is not possible with the FileInputStream or FileOutputStream. RandomAccessFile file = new RandomAccessFile("c:datafile.txt", "rw"); To read or write at a specific location in a RandomAccessFile you must first position the file pointer at the location to read or write. This is done using the seek() method. The current position of the file pointer can be obtained by calling the getFilePointer() method. RandomAccessFile file = new RandomAccessFile("c:datafile.txt", "rw"); file.seek(200); long pointer = file.getFilePointer(); file.close();
  • 16. 16 Reading from a RandomAccessFile Reading from a RandomAccessFile is done using one of it many read() methods. RandomAccessFile file = new RandomAccessFile("c:datafile.txt", "rw"); int aByte = file.read(); file.close(); The read() method reads the byte located a the position in the file currently pointed to by the file pointer in theRandomAccessFile instance.
  • 17. 17 Writing to a RandomAccessFile Writing to a RandomAccessFile can be done using one it its many write() methods. RandomAccessFile file = new RandomAccessFile("c:datafile.txt", "rw"); file.write("Hello World".getBytes()); file.close(); Just like with the read() method the write() method advances the file pointer after being called. That way you don't have to constantly move the file pointer to write data to a new location in the file.
  翻译: