Meaning : File handling is the process of managing data file(s). It organizes the files
by storing and retrieving data to and
from the data file.
File : File is the
collection of related data and information in a computer. There are two types
of file.
(i)
Program file : It is the collection
of commands and keywords sequentially, in order to solve a particular problem.
Program file is developed in programming language. It has an extension .BAS,
.PRG,. CPP etc.
(ii)
Data file : It the collection of
data under different fields of a particular topic stored in computer It is linked with program file. There are two types of data file. They are
(a)
Sequential access data file : The
data file where data are organized in form of records sequentially, one after
another. It access the records from top to bottom orderly unless end of file.
Advantages:
*.
It is simple and natural way of managing data.
Disadvantages:
*.
It is very slow and very difficult to update the data
(b)
Random Access data file : The data
file where data are accessed randomly without any sequence of record is called
random access data file. The address of each record is derived from the key
field called record pointer.
Advantages:
*.
Direct access of record is possible, thus faster.
*. Files can be easily maintained up to date.
Disadvantages:
*.There
is danger of data corruption and deletion.
Modes of opening data file :
The
way or purpose of the file to be opened is called file mode. Data file are
opened to carry out the following activities.
*.To
write /store data
*.To
retrieve/read data
*.To
append/add data
There
are three modes of opening data file. They are
(i)
Output mode : Data file is opened
in this mode,in order to write or store data to the sequential data file.
(ii)
Append mode : Data file is opened
in this mode, to add/append data at the
end of existing data file.
(iii)
Input mode : Data file is opened
in this mode, to read or retrieve data from sequential data file.
Keywords related to data
file:
(i)
OPEN: This statement is used to open the data file
for reading or writing or adding data to the data file. It creates buffer to
the memory for I/O operation.
Syntax:
OPEN<file$> FOR MODE AS #<FILE NUM>
(ii) CLOSE : It terminates or closes all
open data files
and devices.
Syntax
: CLOSE #<FILE NUM>,#<FILENUM>,…
(iii)
WRITE # : This statement is used to
write/store data to the sequential data file.
Syntax:
WRITE#<FILE NUM>,data,……
(iv)
PRINT #: : It is also used to write/store data to the
sequential data file.
Syntax:
PRINT#<FILE NUM>,data,……
Difference between WRITE# and PRINT#
WRITE# writes the data by enclosing string data in
quotation marks and separates each data by comma., where as PRINT# does not
enclose string data in quotation marks, nor it separate each data by comma.
(v)
INPUT# : It reads each data from
sequential data file and store them to the corresponding variables.
Syntax:
INPUT #<FILE NUM>, Variable list,…
(v)
LINE INPUT# : It reads entire line/complete record ( maximum 255
characters) from data file and store them in a string variable.
Syntax:
LINE INPUT #<FILE NUM>,String var.
(vi)
FILES: It displays all the files of
current drive.
Syntax: FILES<Path$>
Eg : Files “c:\qbasic”
(vii) SHELL: It is used to go to DOS prompt temporarily..
Syntax: SHELL
(viii)
KILL : It deletes the file(s) from specified
drive and path.
Syntax: KILL <Path$>
Eg : KILL “c:\qbasic\tt.dat”
(ix)
SYSTEM: It is used to close Qbasic
program.
Syntax: SYSTEM
(x)
MKDIR: It is used to create sub
directory in specified drive and path.
Syntax: MKDIR<Path$>
Eg : MKDIR “c:\qbasic\QB”
(xi)CHDIR: It is used to change into
current directory.
Syntax: CHDIR<Path$>
Eg : CHKDIR “c:\qbasic\QB”
(xii)
RMDIR: It is used to remove sub directory.
Syntax: RMDIR<Path$>
Eg : RMDIR “c:\qbasic\QB”
(xiii)
NAME …AS : It is used to rename file.
Syntax: NAME <OLD FILE> AS <NEW
FILE>
Eg. Name “Temp.dat” AS “book.dat”
(xiv) INPUT$() : It reads the specified number of character from each
record of data file.
Syntax:
INPUT$ [n%, #<File Num>]
Eg.
INPUT$ (4, #2)
(xv) EOF() : It is a flag
which tests end of file.
Syntax : EOF<File num>
Eg : EOF(2)
0 Comments