Sensitivity: Internal & Restricted
•System.outsendstheoutputtothestandardoutput stream,whichisconsolebydefault.
•System.err sends the output to the standard error stream, which also happens to be
console by default
•Thereasonbehindhavingtwoseparatestreamsforoutputanderroristhatthestandardo
utputshould beusedforregularprogramoutputswhilestandard
errorshouldbeusedforerrormessages.
DifferencebetweenSystem.outandSystem.err
Sensitivity: Internal & Restricted
•Boththesestreamscanberedirectedtodifferent destinations.
•Wecanredirecttheprogramoutputto a particularlogfileandtheerrormessagestoanother
logfilebyusingthefollowingsyntax:
javaStreamDemo>output.log2>error.log
(whereStreamDemoisthenameoftheclass)
Duringexecution,theprogramoutputwill be stored in output.log while the error message(if
any) will be stored in error.log
System.outandSystem.err(Contd.).
Sensitivity: Internal & Restricted
ByteStreams
InputStream OutputStream
I/OStreamshierarchy
FileInputStre
am
ObjectInputStrea
m
BufferedInputStre
am
ManyMoreInputStreamclas
ses
ManyMoreOutputStreamclas
ses
FileOutputStrea
m
BufferedOutputStrea
m
ObjectOutputStre
am
Abstract
c lass
Abstract
class
Sensitivity: Internal & Restricted
CharacterStreams
Reader Writer
I/OStreamshierarchy(Contd.).
FileRead
er
InputStreamRea
der
BufferedRea
der
ManyMoreReaderclasses ManyMoreWriterclasses
FileWriter
BufferedWrit
er
OutputStreamWrit
er
Abstrac
tclass
Abstract
class
Sensitivity: Internal & Restricted
Toread&writedataintobuffer
ByteStreamclasses
Toread&writedataintofile
Toread&writeobjectinto
secondarydevice(serialization
)
FileInputStream
FIleOutputStream
BufferedInputStream
BufferedOutputStrea
m
ObjectInputStream
ObjectOutputStrea
m
Sensitivity: Internal & Restricted
To read & write data into buffer
Character Stream classes
To read & write data into file
Bridge from character stream
to byte stream
FileReader
FIleWriter
BufferedReader
BufferedWriter
InputStreamReade
r
OutputStreamWrit
er
Sensitivity: Internal & Restricted
1.Java input output classes are available in ___________package
a.java.lang
b.java.io
c.java.util
2.What are the inbuilt streams available in java.io package
a.System.in
b.System.out
c.System.err
d.All of the above
3.Can data flow through a given stream in both directions?
a.Yes
b.No
Quiz