CBSE Class 12 Computer Science Question 59 of 145

File Handling — Question 20

Back to all questions
20
Question

Question 20

Which of the following command is used to open a file "c:\pat.txt" for writing in binary format only ?

  1. fout = open("c:\pat.txt", "w")
  2. fout = open("c:\\pat.txt", "wb")
  3. fout = open("c:\pat.txt", "w+")
  4. fout = open("c:\\pat.txt", "wb+")
Answer

fout = open("c:\\pat.txt", "wb")

Reason — The syntax to open a file for writing in binary format is f = open("c:\\temp\\data.txt", "wb"). Hence according to this syntax fout = open("c:\\pat.txt", "wb") format is correct.