0% found this document useful (0 votes)
24 views10 pages

File Handling in Java

The document discusses file handling in Java, specifically focusing on reading from and writing to binary files. It includes examples of methods for saving data to a file and retrieving it, as well as checking the availability of products using a product code. The document outlines the structure and syntax for implementing these functionalities in Java code.

Uploaded by

fivopew106
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views10 pages

File Handling in Java

The document discusses file handling in Java, specifically focusing on reading from and writing to binary files. It includes examples of methods for saving data to a file and retrieving it, as well as checking the availability of products using a product code. The document outlines the structure and syntax for implementing these functionalities in Java code.

Uploaded by

fivopew106
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Whot in fle handing ?

Cours
a-s theve ave
’White as. ite fles.
You
Fle os0Tot fles .tt)
Jawa
| Birany flu (dat)
(Reace
Tut file Brog
Can
ile Handingi in Jawo

ave
’RunPogam lost
output
thes vans
valnes Or dat
we want to Sawe
So,Somuswe sothat we Can

n.. ..
DWAP to Save name ivto a tent fle frit tt
clas ile hite
þuble
Wite fu= nw ikwito ("fuit.bt );
File
bw = new blfevdlaileJu
new
Priniter pw

pu printtn (Kiwi ");


ad fron
2) WAP to nnd Jrom a tont fle that you haue alady
(estud in the previes roga Reodsfutet
clas FleRend hrates
kii

void main (S1ig angl )trous loEncftiom


þublic stotic
{ Flekeodun - New Flelender ("fruits.tt')

Stig ni
shile' ln bn. nadline ())! =rull)
SoPln Cn);
3
5); bt( wnite dos.
C"Ajy; iteUTF das.
DataButptStream
new =dos
(fas; stua lutput Dota
utputstrcanl"ab.
dat') new
lofxuffion throus [) ang Shig mainl void stotc bablc
White File Döta clas
io. java.impert
dot) obe. fle dota
binay name your witt towAP 3)
ainto manks and
abe-dot
4)wAP to rad from the data jile- obc.
obe dat
imfodjaueio"; 2

clas RendData Samn

patlie stathe void main bing ongl) tuas Iobxcapti


Stram Jis nw file gutsorom ('abe - dat
SAleut
LDatasut Strean dä New
shile (lee)
Sbang n di. nead uTFC);
int Umdi.nuodst)
SOPln"Nane ='+n+"ln Marts ="tm)
coteh (EoFExcuttim e)

AAAA A AARg
A binary file named ABC.DAT" contains the product code (pc), unit price (up) and
quantity() for number of items.
Write a Method to accept a product code 'p' and check the availability of the product
and display with an appropriate message.
The method declaration is as follows:

void findpro( int p)


S) void yindrolid ) thwrous loExeyhon
new ilahbud Streon (AGC- DOT);
Dataiut Styeam dis es DataspdStrn(fis);
booluan e - falaj
uhik
int pe dis.neadst );
int da. uodst ();
int
Sorac" Produet fand");
Sofn(odud coda- "h);
Sorn (" nit pia "u);
Sopn "luany);

3
3
catch (CoFBuauptien e)
g)
3
Sopnc" Pro duct nt ound ;

You might also like