You are on page 1of 2

in java user pasethi value leva mate we have to use two ways:

1)Scanner class
2)BufferReader

File handling:

To store the data in the file we have to WRITE (write) method .we have to pass data

What write? text,byte,UTF

UTF:type of format data will be save

to store the data we have to create writeUTF ..whatever you want to store the data
writeUTF method belongs to Dataoutputstream . so we have to create the object.

in order to crate dataoutputstream we have to create fileoutputstream obj. it has


asked to file name
and you need to pass this obj in dataoutputstream.

there might be some promblem to crate those file demo.txt or some problem might be
writeUTF so we will give error so we have to handle those error through try and
catch or throws exception

so file will be successful .it is encrypted formate. so open with word file

read this content we have to say method called name readUTF. it returns the string
to retrive the data we have to create datainputstream.same as like dataoutputstream
like wise fileinputstream no obj create karvano

~~>we have to first create the file ..using fileoutputstream


in fileoutputstream we need to store some data so we need to create the writeUTF
but ana mate dataoutputstream no obj we want .so first we create dataoutputstream

to read the data first which file we have to read so first we declare using
fileinputstream

retrive the data using datainputstream and storing and convertdata into string and
print it

File f=new file("File name");//why we can use because i here two time we can write
file name but what if i want to change file name i have to write 2 times . so ana
karta file no object create karine
obje pass kari nakhvano so file name change karvano hoy to khali 1 time j lakhvu
pade..

properites files:when you work on project you need some configuration or files.like
spring,hibernate...
we have to use xml file but some people work on properties file
in one file we have multiple key and multiple values

properties is inbuilt class in java and working like hashtable


we have to store the data so we can use outputstream obje = new
fileOutputstream(dataconfig.prop);
p.setproperty ("url",localhost:3306/mydb");

fetch the data we can use InputStream . and load the file and print the data and
method we can use getProperty("url/password/uname");
File Management :

Real life software projects maintains large amount of data


for examples:Records related to
Students,Exams,Employees,products,Places,Temperature,etc..
File is a location on disc where data is sorted..
Java programming provides many classes and methods to manage such data files..

File class has many useful methods for managing files..


createNewFile(): creates an file
canWrite():checks whether the file is writable or not
getAbsolutePath():Returns the absolute pathname of the file
length(): Returns the size of the file in bytes
mkdir():creates a directory

You might also like