Access the latest CBSE Class 12 Computer Science File Handling Worksheet Set A. We have provided free printable Class 12 Computer Science worksheets in PDF format, specifically designed for File Handling. These practice sets are prepared by expert teachers following the 2025-26 syllabus and exam patterns issued by CBSE, NCERT, and KVS.
File Handling Computer Science Practice Worksheet for Class 12
Students should use these Class 12 Computer Science chapter-wise worksheets for daily practice to improve their conceptual understanding. This detailed test papers include important questions and solutions for File Handling, to help you prepare for school tests and final examination. Regular practice of these Class 12 Computer Science questions will help improve your problem-solving speed and exam accuracy for the 2026 session.
Download Class 12 Computer Science File Handling Worksheet PDF
1. Data File Data files are the files that store and preserve data released to a particular application.
Computers store every file as a collection of 0s and 1s, i.e. in binary form. Therefore, every file is basically just a series of bytes stored.
2. Text File It is a sequence of characters consisting of alphabets, numbers and other special symbols.
It stores information in ASCII characters. In text file, each line of text is terminated with a special character known as EOL (End of Line) or delimiter.
The file extension of text file is .txt.
(i) Opening a File In file handling, the first requirement is opening a file. Once a file is opened, read, write, append, close, etc., can be performed on the file. To open a file, open() method is used in Python.
(ii) Closing a File It is important to close files as soon as you have finished your work with file.
Opened file is closed by calling the close() method of its file objects.
(iii) Writing into Files For writing to a file, we first need to open it in write or append mode. In Python, there are two methods of file objects which are used to write data into a files.
• write() This method takes a string and writes it into the file. This method does not add a newline character (‘\n’) to the end of the string.
Syntax <FileHandle>.write(str1)
• writelines () Whenever, we have to write a sequence of string to a file, we will use writelines() instead of write().
Syntax <FileHandle>.writelines(L)
(iv) Reading from Files After writing information into a file, you must need to read that data at some point. Python provides mainly four types of read methods to read data from file.
• read() This method returns a string containing all characters in a file.
Syntax <FileHandle>.read()
• read([size]) This method specifies how many characters the string should return.
Syntax <FileHandle>.read(n)
• readline() This method will read from a file line by line. For readline(), a line is terminated by ‘\n’ or End of Line (EOL) (i.e. new line character). When end of file is reached, readline() will return an empty string.
Syntax <FileHandle>.readline()
• readlines() This method will return a list of strings, each separated by ‘\n’.
This method reads all rows and retains the newlines character that is at the end of every row.
Syntax <FileHandle>.readlines()
(v) flush() Method This method will force out any unsaved data that exists in a program buffer to the actual file.
Python automatically flushes the files when closing them. But you may want to flush the data before closing any file.
Syntax FileObject.flush()
(vi) Random Access Methods Python provides two methods to perform random access operations in a file. These methods help you to manipulate the position of file pointer and thus you can read and write from desired position in the file.
• tell() Method This method tells you the current position within the file, measured in bytes from the beginning of the file.
Syntax File0bject.tell()
•seek() Method This method can be used to change the current position in a file. This method does not return any value.
Syntax File0bject.seek(offset[,mode])
3. Binary File It is a file that contains information in the same format as it is held in memory. In binary files, no delimiters are used for a line and no translations occur here. They represent the actual content such as image, audio, video, executable files, etc. These files are not human readable. The file extension of binary file is .dat.
(i) Working with Binary File Python object handles the binary files. Python provides a special module-the pickle module which can be used to store any kind of object in file.
(ii) Using dump( ) Method This method is used to write objects to a file. Before use the dump( ) method, you first have to import the pickle module.
Syntax
import pickle
......
......
......
pickle.dump(object_to_pickle,File0bject)
(iii) Using load() Method
This method is used to load data from a binary file.
Syntax
import pickle
......
......
......
object=pickle.load(File0bject)
4. CSV File CSV (Comma Separated Values) format is one of the most simple and common ways to store data in tabular form. Each record consists of one or more fields separated by commas. To represent a CSV file, it must be saved with the .csv file extension.
(i) Working with csv file csv files are used to store a large number of variables or data. They are
incredibly simplified spreadsheets. Each line in a csv file is a data record.
(ii) Read from CSV File Using csv.reader() To read data from csv files, you must use the reader() function to generate a reader object.
This function returns a reader object which is an iterator of lines in the csv file.
Syntax csv.reader(<FileHandle>)
(iii) Write into a CSV File Using csv.writerow() To write an existing file, you must first open the file in one of writing modes (w, a or r+) first. For this, writerow() function is used in Python for csv files.
This function writes items in a sequence (list, tuple or string) separating them by comma character.
Direction (Q. Nos. 1-15) Each of the question has four options out of which only one is correct.
Select the correct option as your answer.
1. To read three characters from a file object f, we use ……… .
(a) f.read(3)
(b) f.read()
(c) f.readline()
(d) f.readlines()
Answer : A
2. How do you get the current position within the file?
(a) fp.seek()
(b) fp.tell()
(c) fp.loc()
(d) fp.pos()
Answer : B
3. The files that consists of human readable characters
(a) binary file
(b) text file
(c) Both (a) and (b)
(d) None of these
Answer : B
4. Which function is used to write a list of string in a file?
(a) writeline()
(b) writelines()
(c) writestatement()
(d) writefullline()
Answer : A
5. What will be the output of the following Python code?
myFile = None
for i in range (8):
with open(“data.txt”, “w”) as myFile:
if i > 5:
break
print(myFile.closed)
(a) True
(b) False
(c) None
(d) Error
Answer : A
6. What is the use of seek() method in files?
(a) Sets the file’s current position at the offset
(b) Sets the file’s previous position at the offset
(c) Sets the file’s current position within the file
(d) None of the mentioned
Answer : A
7. What will be the output of the following Python code?
myFile = open(“story.txt”, “wb”)
print(“ Name of the file: ”, myFile.name)
myFile.flush()
myFile.close()
(a) Compilation error
(b) Runtime error
(c) No output
(d) Flushes the file when closing them
Answer : D
Suppose the content of the file ‘‘story.txt’’ is
Education Hub
Learning is the key of success.
8. What is the output of following code?
myfile=open(‘story.txt’,‘r’)
s=myfile.read(10)
print(s)
s1=myfile.read(15)
print(s1)
myfile.close()
(a) Education
Hub Learning is
(b) Education
Hub
Learning is
(c) Education
Hub
Learning
is
(d) Education Hub
Learning is
Answer : B
9. What is the output of following code?
f=open(‘story.txt’, ‘r’)
s=f.readline()
lcount=len(s)
print(lcount)
f.close( )
(a) 4
(b) 2
(c) 1
(d) 8
Answer : B
10. What is the output of following code?
f=open(‘story.txt’, ‘r’)
str=“ ”
s=0
ts=0
while str:
str=f.readline()
ts=ts+len(str)
print(ts)
f.close()
(a) 44
(b) 43
(c) 37
(d) 45
Answer : A
11. What is the output of following code?
def test () :
s=open (“story.txt”, “r”)
f=s.read()
z=f.split( )
count=0
for i in z:
count=count+1
print(count)
(a) 7
(b) 8
(c) 5
(d) 9
Answer : B
Suppose the content of file ‘‘Para.txt’’ is
Education Hub
Electronic learning
Learning is the key of success
12. What is the output of following code?
def test() :
f=open (“Para.txt”, “r”)
lines=0
l=f.readlines( )
for i in l:
if i [0] = = ‘E’ :
lines+=1
print(lines)
(a) 2
(b) 1
(c) 3
(d) Error
Answer : A
13. What is the output of following code?
def myFunc() :
f=open (“Para.txt”, “r”)
count=0
x=f.read()
word=x.split()
for i in word:
if (i!=“learning”):
count=count+1
print(count)
myFunc()
(a) 2
(b) 10
(c) 8
(d) Error
Answer : C
14. What is the output of following code?
def test():
f=open(“Para.TXT”)
n1=0
n2=0
while True:
l=f.readline()
if not l:
break
for i in l:
if (i==‘E’ or i==‘e’):
n1=n1+1
elif(i==‘C’ or i==‘c’) :
n2=n2+1
print(n1)
print(n2)
f.close()
(a) 8
5
(b) 8
4
(c) 3
7
(d) Error
Answer : A
15. What is the output of following code?
def Func():
with open(‘Para.txt’, ‘r’) as f :
l=f.readlines()
f.close( )
print(l)
del l[3]
print (l)
f=open (‘Para.txt’, ‘w’)
f.writelines(l)
f.close( )
(a) Delete the 3rd word from file
(b) Delete the 4th word from file
(c) Delete the 3rd word from file at end
(d) Error
Answer : B
Please click on below link to download CBSE Class 12 Computer Science File Handling Worksheet Set A
| CBSE Class 12 Computer Science Boolean Algebra Worksheet |
| CBSE Class 12 Computer Science C++ Worksheet Set A |
| CBSE Class 12 Computer Science C++ Worksheet Set B |
| CBSE Class 12 Computer Science Classes And Objects Worksheet |
| CBSE Class 12 Computer Science Communication Technology Worksheet |
| CBSE Class 12 Computer Science Data Base Concept Worksheet |
| CBSE Class 12 Computer Science Data File Handling Worksheet |
| CBSE Class 12 Computer Science File Handling Worksheet Set A |
| CBSE Class 12 Computer Science File Handling Worksheet Set B |
| CBSE Class 12 Computer Science File Handling Worksheet Set C |
| CBSE Class 12 Computer Science Function In Python Program Worksheet |
| CBSE Class 12 Computer Science Functions Worksheet Set A |
| CBSE Class 12 Computer Science Functions Worksheet Set B |
| CBSE Class 12 Computer Science Implementation of Queue Worksheet Set A |
| CBSE Class 12 Computer Science Implementation of Queue Worksheet Set B |
| CBSE Class 12 Computer Science Implementation of Stack Worksheet |
| CBSE Class 12 Computer Science Inheritance Worksheet Set A |
| CBSE Class 12 Computer Science Inheritance Worksheet Set B |
| CBSE Class 12 Computer Science Sql Worksheet Set A |
| CBSE Class 12 Computer Science Sql Worksheet Set B |
| CBSE Class 12 Computer Science Using Python Libraries Worksheet |
Important Practice Resources for Class 12 Computer Science
File Handling CBSE Class 12 Computer Science Worksheet
Students can use the File Handling practice sheet provided above to prepare for their upcoming school tests. This solved questions and answers follow the latest CBSE syllabus for Class 12 Computer Science. You can easily download the PDF format and solve these questions every day to improve your marks. Our expert teachers have made these from the most important topics that are always asked in your exams to help you get more marks in exams.
NCERT Based Questions and Solutions for File Handling
Our expert team has used the official NCERT book for Class 12 Computer Science to create this practice material for students. After solving the questions our teachers have also suggested to study the NCERT solutions which will help you to understand the best way to solve problems in Computer Science. You can get all this study material for free on studiestoday.com.
Extra Practice for Computer Science
To get the best results in Class 12, students should try the Computer Science MCQ Test for this chapter. We have also provided printable assignments for Class 12 Computer Science on our website. Regular practice will help you feel more confident and get higher marks in CBSE examinations.
You can download the CBSE Practice worksheets for Class 12 Computer Science File Handling for the latest session from StudiesToday.com
Yes, the Practice worksheets issued for File Handling Class 12 Computer Science have been made available here for the latest academic session
There is no charge for the Practice worksheets for Class 12 CBSE Computer Science File Handling you can download everything free
Regular revision of practice worksheets given on studiestoday for Class 12 subject Computer Science File Handling can help you to score better marks in exams
Yes, studiestoday.com provides all the latest Class 12 Computer Science File Handling test practice sheets with answers based on the latest books for the current academic session