Generally, in JAVA programming we write two types of applications or programs. They are volatile or non-persistent program and non-volatile or persistent program.
If we store the data permanently in the form of a file, then the data of that file can be modified by any unauthorized user. Hence, industry always recommends not storing the data in the files. Since, files do not provide any security. Hence, industry always recommends storing the data in the form of database. Since, most of the popular databases provide security in the form of user names and passwords.
In order to store the data permanently in the form of files we must use or import a package called java.io.*
Types of operations or modeson files:
On files we perform two types of operations they are read mode and write mode. The following diagram will illustrate how to open the file either in read mode or in write mode or in both modes:
Types of streams in JAVA:
Based on transferring the data between primary memory to secondary memory and secondary memory to primary memory. In JAVA we have two types of streams they are byte streams and char streams.
Byte streams are those in which the data will be transferred one byte at a time between primary memory to secondary memory and secondary memory to primary memory either locally or globally. java.io.* package contains some set of classes and interfaces which will transfer one byte at a time.
Input Stream class:
This is an abstract class; hence we cannot create an object of this class directly. This class is basically used to open the file in read mode. In this class we have the following methods:
1. public int read (); 2. public int length (); // 3. public int available (); 4. public void close ();
total size of the file
// available number of bytes only
In JAVA end of file (EOF) is indicated by -1.
Output Stream class:
This is also an abstract class; hence we cannot create an object of this class directly. This class is used for opening the file in write mode. In this class we have the following methods:
1. public void write (int); 2. public int length (); 3. public void available (); 4. public void close ();