Question Answers on File Handling

Print This Page


  1. What is file handling ?

Ans :

File handling is a process to create a data file, write data to the data file and read data from the specified data file.

2. Define File


The collection of different data or information or instructions wich is stored in secondary storage devices under a unique file name is known as file .. in q baasic there are two types of file

a. Data file

b. program file

3. differentiate between data file and program file .


Data file is a collection of data such as name , address ,phone , etc required for data processing . in an data file , related data of a person , product or any things  are stored in a  row known as a record . data file is stored sesperately from the program file . it provides data to the program files.

Program file is a set of instructions written in a computer language for data processing under unique file name . A program file contains instructions which are used to manipulate data and give the output . Program files of Qbasic has .BAS extension.

4. Write some advantages of data file.


Advantages are :


  • The data stored in data file can be reused
  • it is possible to use single data file by different programs
  • it provides flexibility to recover saved data whenever required
  • data files can be created , modified or deleted

5. Explain different types of data files used in QBASIC.


1. Sequential data file

  • Performs reading and writing operations sequentially from the beginning to the end of file
  • Records need to be accessed in same order as they are stored.

2. Random access data file

  • Performs reading and writing operations randomly in any order.
  • Records can be accessed directly in any order

6. What is file mode ?  List Different file modes in QBASIC


The purpose of opening data files is called file mode.  The Common modes of opening data files are :

Mode Purpose
OUTPUT Creates a new sequential file and writes data in it. It starts writing data always from the beginning of the file.
INPUT Reads /displays data from the existing data files .
APPEND It adds more records in the existing data file . It starts adding data from End of file.


Mode File Exists File Does not exists
OUTPUT mode or “O” Creates a new file Creates a new file
INPUT mode “I” opens the existing file creates a new file
APPEND or “A” opens the existing file  error message “file not found”


7. Write down the purpose of the following statements and functions :


OPEN statement :

> The OPEN statement is used to open sequential data file for writing data to the data file or reading data from the data file using Output , Input , or Append mode .

 WRITE # statement 

The WRITE # statement is used to send or store one or more data items to the specified file using either output or append mode .

Example : WRITE #2 ,N$,B$,C

CLOSE and CLOSE # statement

The CLOSE statement is used to close one or more opened data file. The CLOSE# Statement is used to close one or more opened data file . The CLOSE # is used to close only specific files.

INPUT # statement

The INPUT# statement is used to read data of the existing sequential data file and stores them in a variable . it reads data of the file in the same order as they are stored.

Example : INPUT #2,N$,B$,C


LINE INPUT # Statement

The LINE INPUT # statementreads the entire line or maximum 255 characters from the keyboard or sequential file. It accepts special characters such as commas , quotes , slashes and other which the INPUT stateents doesn’t allow and stores data only in string variable .

Example : LINE INPUT#2, A$


The EOF() function is used to check the end of file marker while reading the data from the open sequential file . it returns true if the end of file has been reached and returns FALSE  when the end of file has not been reached.

Example : EOF(1)


The INPUT $ Statement returns a specified number of characters from a data file .



The FILES Statements displays the list of files names of a currend directory .

Example : FILE(filespecs)

NAME …. AS….

The name statement is used to rename a file .



The KILL statement is used to delete a file from the specified disk or directory

Example : KILL “ABC.DAT”


The MKDIR statement is used to create new directory in a specified location to manage a file.

Example : MKDIR(“D:\QBASIC”)



The CHDIR is used to change the default directory on a specified drive location.

Example : CHDIR (“D:\MyProjects”)


The RMDIR statement is used to delete a directory from a disk. It can remove only empty diretory.

Example RMDIR “D:\MyProjects”


1 OPEN OPEN “FILENAME.DAT” FOR <MODE> AS #FILE NUMBER OPEN statement opens a sequential file for one of the three possible operations (I, O, A)
2  INPUT #  INPUT # File number, variable list Allow to read the data from an opened sequential data file.
3  CHDIR  CHDIR “location name”  To change current the directory
4  MKDIR  MKDIR “path” To make a new directory
5  RMDIR  RMDIR “Path” To remove directory
6  KILL  KILL “File name” To delete files from specified location
7  LINE INPUT # LINE INPUT # File number, Variable List  Used only for string input
8  PRINT #  PRINT #File number, Variable List  Used to send values to the data file
9  INPUT$()  INPUT$(N,#File number)  Reads specified numbers of characters from a data file.
10  FILES  FILES(Specs)  To display the list of files
11  EOF()  EOF(File Number)  Used to find out end of the data file which occurs after the last record.
12  NAME AS  NAME”old name”AS”new name” to rename file or directory on a disk
13  WRITE# WRITE # File number, Variable list  The WRITE statements sends one or more data items to the specified file (to write data on a sequential file)
14  CLOSE#  CLOSE #File number  It Close the file after Input Output operation







Leave a Reply