File Handling in JAVA

faq:

Define ‘File” class :-

=>’File’ class is from ‘java.io’ package and which is used to find the properties

of the file like file_path, file_name, file_length, file_exist or not,…

syntax:

File f = new File(“fPath&fName”);

*imp

Object Storage with File Storage:

=>when we want to record Object Storage onto File Storage,the Object Storage

must be available in the form ‘Binary Stream’.

Define Serialization process :-

=>The process of conveting Object State into binary Stream is known as

Serialization process.

=>we use writeObject() method from ‘java.io.ObjectOutputStream’ class to perform

Serialization process.

Method Signature:

public final void writeObject(java.lang.Object) throws java.io.IOException;

syntax:

ObjectOutputStream oos = new ObjectOutputStream(fos);

oos.writeObject(ob);

Define DeSerialization process :-

=>The process of converting binary Stream into Object State is known as

DeSerialization process.

=>we use readObject() method from ‘java.io.ObjectInputStream’ class to perform

DeSerialization process.

Method Signature:

public final java.lang.Object readObject() throws java.io.IOException;

synyax:

ObjectInputStream ois = new ObjectInputStream(fis);

Object o = ois.readObject();

Note:

=>To perform Serialization and DeSerialization process the class must be

implemented from ‘Serializable’ interface.

faq:

Define Serializable :-

=>Serializable is an interface from ‘java.io’ package and which specify the

Serialization and DeSerialization process.

=>This Serializle is an empty interface because which donot have any members

and which is also know as Marking Interface or Tagging Interface.

Summary:

Types of Streams:

(i)Binary Stream(Byte Stream)

(ii)Character Stream

Classes related to Binary Stream:

(i)DataInputStream

(ii)DataOutputStream

(iii)FileInputStream

(iv)FileOutputStream

Classes related to Character Stream:

(i)BufferedReader

(ii)FileReader

(iii)FileWriter

Classes Serialization and DeSerialization:

(i)ObjectInputStream – readObject() method

(ii)ObjectOutputStream – writeObject() method

DisAdvantage of FileStorage:

1.Data Redundancy

2.Data Inconsistency

3.Difficuilty in Accessing Data

4.Limited Data Sharing

5.Integrity Problems

6.Atomicity Problems

7.Concurrent Access Anomalies

8.Security problems

1.Data Redundancy:

=>It is possible that the same information may be duplicated in diff files and

leads to data redundancy.(memory wastage)

2.Data Inconsistency:

=>Because of data redundancy,it is possible that data may not be in consistant

state.

3.Difficuilty in Accessing Data:

=>Accessing data is not  easy to do and efficient in file processing Systems.

4.Limited Data Sharing:

=>In file-based-storage the data is available in Scattered form and difficult to

share the data.

5.Integrity Problems:

=>Integrity is not possible in File-based-storage becuase the data is available

in scattered form.

6.Atomicity Problems:

=>Any operation on database must be atomic,which means it must happen entirely

or not at all.

=>which is not possible in File-based-Storage.

7.Concurrent Access Anomalies:

=>Multiple users are allowed to access data simultaneously and this is for

better performance and faster response.

=>which is not possible in File-based-storage.

8.Security problems:

=>Security is very high in DB and which is not possible in File-based-storage.

Note:

=>In realtime File Storage cannot be the Major storage formapplications because of

above DisAdvantages.

=>All the above DisAdvatages can be Overcomed using DataBase Storage.

Leave a Comment

Your email address will not be published. Required fields are marked *