You are on page 1of 15

2,

Byte Strtamu
BytSrcanms uanty the data in he Jotm of fndvidual byt
-Byte 3treama cay fnthen valus &at andu m 0-255
&reams ana weul to harlle teat, mades, audto
video
h a two A0p abstract danes o Byle reams

1) Inut tam

)Output Shea

bye A-hpukStrea
/Pele Lnput Shrtan DadanputSheam
bjectloput 8trta Lne urnbeopugham
nput &treom Ctlten nput rar
Bauud IopukShream
Colstrack clan)Ppedlo put gtrcan Paahlock.nput 9tream
Seguneapuk Stream
Shringbulteloput
8ean
tbh levd Sream.

Low level 9tramn


Methods oputStran.
fnt uad ( bykti b)
Reads Aomt. qoup o byte ond Atdu irto on aua b

alksta ct int uodt )


It eads te eat byte dr dala Hom input Atream
3 nt avaslablk ()
IExututns the number ot byte in te il
n Au (lovng n)
Ove and dscasds nnunben of ytu tm p &tream.
atp
void clox ()
closs ti 1lp strcam laases ay Asum uocu amouated
with ee stuam

voí d maak (int adumt)


6
4boolean mankSuppkkd ) 8voio
nva.fo packae

(owiu dolo
Aatveam 18 o ou o data. A ateom
om on plase to ano ther
» uive te olo o n tnput
3ttama mul
devita and nd e chlo to an outpud deyiu
Streama Can be calepbctzed into fnpu adput sbrearns
- Input trcami heod -e dolo. unrn

}le edc.
kybeand ,

rmonsteta t.
he dala to he
Srcams wyd te
Output
- A he atrtarn clanu u avaslabe in jova io poco

types o svams, Tho


oe:
-Thow a

Byte Streams
. Chanasker Sram.

IO

Chanud &romns
Byle &rcams

Wsto
Reodan
lnputSbrcam Output Sfrean
(o -65535)
Co- 255) UNICDDÉé

ASCI
31

Byle Aray OdputSrearn


7fllQukputheam DalaCulput8Brtan

Output hrtam FHen OudputCrtam Print&rea


Calshact dam) Bullnd OutpukSheam
OjutOtputSrtarmn

Prped Ou-put Shrean


high level streamu

Lo leve streama

Methods ulpuut Ltrcam


abstrart void wonite (tot b)
wi tes the speusHid byte to te outpuk afrean.

void u i t (tyeti b)

.ngth bytes Auan the Apetiked byk amayH


oudput Stream

id fush)
Puhes hi output Sheam and fdus any butad op

wten ouk u e s to wste data tn to


bytes tbbe
tne

vofd clo)
atbiam a ulsasns an4 A4it
oss ouput
anouated th stu
HaAOUMA
-Ala is a clan tm java.fo

-Itaunnt a and d'utsu path nomis .

- Usinq bnow he propenHea ot Fu and


Fl da we tan

delmatiu o danpoah

Raading e dala m a

impdtt Java.io.,
public cla flkkead

pubic sati vold moin(tig ant3) twows 10¬upliom

Ale w rleCabc. but"),


talopukShream tsnew Aelopetrean (+);

ohile K-fts-vead ()) !: -\)

Systurn.out piot (Cchan) k ) ,

Hs.do);

e Fle is not available, we will


whl uadinq t fl ,it
get a cheked euptionPILENOT FOUND ExcePTION'"
pe
clom of all cephon4 in 10pa ckade
-IOEncpHon

Hs. Lad t) 65 A
eaad jav 6
6
D

ABCDE abt.ht
(fale.
Chanat tuams
characteu of eah
uunn daBa a
haoc stuams

Huo byte sbuams

characten Atuams ant apetabzed type or yte


enkual dada.
hot on4 hand
imade, audiolvidu
O
not uutabh d hondUng
chaacen simam suthdt unfcoda charactn et, a t sangu

om 0-65535.
faadu n oUR wo upen abshoct
elanes of

choac AUam
.Readu

9. Wsto.

LinilumberRandu
Butud Resdas
ChasArroy Kaadas
fPenda
Read nputShrearmKeadu
PudhbarkRendaa
(obstact da AluRerdu
RltuRerdey

Prre Roade

grin Reods

buuadhika

ChasArayh u
QulputSteam hkika >#lWsst
wole
Calostiout dloun Alatu
Prped skea

PintWsba
high
Raading e dala tan a sndng o arot F

npot fava. fo. *

Publc co Dmo

pus alatiu void main (Sbing asl3)

uloput Shean 4s nau tlulnputStean ('ob. tat"),


C& Ouptream s : nu Hu0uut &heorn "tt"):
tnt k
whse CCk=4c.xandt)) != -1)

tos.cloC

atch (lNotfound Euytn 4)

)
&ptinout-pnotn(");
cath (l0fnceyHan)

Syntm. out printlo


( );

ava
N

AbC abc. tut

ABC de t
fos( "doP t , uuu);
- Cut append hen
Byte Streams. L

imp6tt java.io.*;
public elam Dem

PLdlic Atatc void main (Stmg ant1) rouu OErption


pgic

HlalnputStrtam =new rlulnput Stream (abe.t );


bis Bufudoputlteam (44s)
-nuo
BubheaednputStream
HleadputIttam yz.tt");
ALOutput Stream ot
= na

bs na buljendOutputSteam (fos);
BuludotputStrcan

fnt k
ohi (Ck= bi*.saad t)) t-1)
bo g.wsdk (k) ; wxitng to y3 ila

Condo.
SysTen.ouk-println (cuhau)k ); l(printing on

fos .clo ) ; cl fos


l elon bos
I clo Pts
bis.lo ); I cloe bís

Deno
boaile Vva
bis. uLad )

+8IS
fos
43 bat
FLS
abt t
we ConMiden onuy Frlenput &tcam, fillout put Shrcam, the CtUso

needs to move om main memdy to Conday memd for

cach haxacta ,A0 in &der to avofd that, we buinq all

Buiheudoputrcan BufJud
o Contentu oto a bulhes airq
CuAput Stram.
* Bufkaadnput Srtan Buuud outpukSeam.
strearns uohith Caunnot open a
Then Ther ane htgh level byte

dine
ercl ghream
aluwa on lbw
y depend
Auloput Stream AleouspukStrcam
a
o shrcam4, we can pa
-As per he uulk o chaining
Louw levelarams objut au a paameta to a high level
Condukot
aha
oljec o ilunput9hrcam namky kr
-Ho t pamed an

atram Conutuehs
8uudnput
a pasameto o e highlevel
Strtam. his mproves he podmanu

while tlosing we must clo all theAtrrama, rst

Output &reama and n input.grams.

impdtt ava.io.*
publi clas Demo
ubl slatc
publie void main (Shing agl1) hsouu louuplion

anpurea Ms- nw fuloputStream('abe.ht );

BultaadInputShtam bise BulkaedlnpatSream ()


nuo

DatalnputShrcan as Ntuv DakaloptSheam (ts);


ALotut8Btarn o new AlLOdput&tream (" ny3 tet );
Butfandasput&team bos enao BufhuadOukpu4Ctream (os)
DalaOulputShream bse Dadadulputtrearn ( bos) ,
nuw

whie( sr -dks.scad lire t)) 1n«ll)


dos.waiBytes (atr);
Suati oul.printo(At),

dos. cle )
s.clok C9:
s clo C)
dts clo O,
bis.clo C)
s. cloC)
Dmo.java i s . dis.uadline )

doa wtkBybeat )

DoS ' pIS

-B1S
-B0s
-Fi
-Pos abe t t
y3tnt

thean BLs Oljeet


imanu,
ue have pamtd kahlevel
m
- f vaid suuk o
DIC Comsbueldand s a
to anoBea
4ghlevel heam

o treams
Chaining
Jeadlinel) DIS eade a ine as a whok and 9etuns it as a

octs.
ndofAu
he
mefhod ehunnd null i
Lt
v s aanira at Compie tSme,
String.
and
deprecated
hadlinet)

eneukes

pvorams
wsib Btu (String) who Une ak-a time in dsttnalon
le.
*ChanadunGrearns.
hanatten atreams.
to
toPY to using low lercl

impot Java. 1o.


publuc clam lelopy

puusic atatk voíd main (String at7) hsous lo Exceptio


Encaptfon

kUReadu Ar new AuRiaduC"abe.t ")


fukidkn [" y3- t t ,
bu)
nw
twe

intk
ohib ((k -tnend ( )) ! -1)

Stu 0ut-prin Ho (l thar ) k);


o-wAk(t)3

ts. clentD;

tand t

L aoc tat
chanarb sbuams. u
Loto leve
4Cap4
t Copu Fl to wain
impdtt Java.fo. *,
puubltc lam Huor
l0ercaption
ahl3) haouu
puLblicslati
void main(4nng

AleReade"abl.tt);
rReadas frenew
Alttu daf-hd ", tu),
le fo

while ((K -tauad() ! -1)


prioto(cehat)
k );
Ssturn cud
o. wste (K)

tuolent)5

impot ava.10. t
cdas Demo
puublc
rouu Onpko.
l0Enuuption
alati vod main (Stung ar3)
public

Sina shr: Java i mp la Ocaan

Shrig Kaad SY u aiReadu (s),


Butteaedkaades br- naww u d Ramdas[ sv),

whi ( sI=
Ls.AaadLine C«)).. nul))

&tar, out.priot ( 31)3


b .don )
SY. clon ) ;
SYSTEM CLASS

0UT s a slati object.


PRINTSTREAMI CLASS CAleti) -

PRINTLN METHOD.

ovos labe in Suptin cdo


r e slandard elda

- Ouut

objut ond it
slandasd InputStream
Sstam.ío: epusnt
epvent shandad hput Devíca.
and it apnunu
out:uhut
Pintsheam objeck
Systüm.
standad o u t Dévíta

Pruntteam Oljck ond


and y
y dlault
dlolt
Stäm-e : epnunt
suprunt
alandad oulpt dausu.
stuout
ue Syatim.ut) Jut t
attach te bafooasd
dada tom e uyboasd
-9o ad he

cdom
to he hputStrtam
ds Doahputlhaan(Sytaro.1n );
Dalanput Stua
nuo

alached to Dada &feam Okjt and wirg i , wa


- kyloard
Can ead dak Comin kfeoasd, uinq ByteSheamn
imot jeava ío.*
pubi clom Demo

publ c alai» voisd maun ( tina ahCJ) uauo oEnap ton

Daalnput Suam dio=


nsus
DadeloutSAam (ysto.in);
Swinga
("entu tent ")
Sein. oud print
strdAsadLine ();
Sstm.out prin tn (sr)'
impot fava. io.
Pubuc clam BulhudDemo

puble Atatc void main (&ting a»li) twous 1oeueptior

I Lowlerel
ALReada fv*nuo tkReaden ('abc.tht)DS
level
Bueud Rendes br nauoBujeudReadeu ( ) | bigh

bws ruw Bulondhse (to);


Bxeudhipse
ging at
br.uadLine () ) } null)
whi ((sth

blo Losk (4);


to give now Line
in y3.ht
Bo.naoline)

Systin. out.prioto ( h);

ueadlin C) emists in ooth DadanputSheam BuhudReades


But nadLine ) ot bujundReadu ît not depretated- Advantage of*

in
1 s Leth bulunqeet eading ect Come4

Butnd Readr.
l Osing ogut loutput Strearn4, the dada ln yooad
Rading

ending it to ilk.

impt Java io. *;

Pubuc clan Demo

pulic atatu void main (tirq anl1)trnowg lOEauption

DalalnputSream
ditnuw DadalnpetSrtam (Sysunio);

SAing at
Sauro.out.printh (" Entor tent);
tr = dis .
uad Line ( );
Spstaro,outprintlnl4k)
ALOutrutStream ossnuo AlkoutpdSream ( "ak.tmt"); //c
DadaOput8hrean ds uo DhaOsrateam Jo)
dbe.wAibbyk«(sr);
3

Ussn Chanaun AreamM, udirq he dadoa tom eyovard.


impdt java.fo.*
publle clon Demo

puic atic void main Shira at )oua O¬nuption

Imut Stheam Reades itY entu nptStreanRerdes (Sntim.in)

Buffd Readss br w e f dKeDdas Cie)

Syatin.uk:prin Ho ("erstu nam ")


Ghrg &t peadlin t);
is + sr)
Syrt-outprintn ("you nam
Syatun. out.pintlo (estu o. ");
4inq g br.headline t ),
tot nbeoe pautnt (s1) ;
stn.out-piotln ( *a);
clort );
3

You might also like