CBSE Class 12 Computer Science Question 66 of 136

Data File Handling — Question 5

Back to all questions
5
Question

Question 5

In which of the following file modes will the existing data of the file not be lost?

  1. rb
  2. ab
  3. w
  4. w + b
  5. a + b
  6. wb
  7. wb+
  8. w+
  9. r+
Answer

'rb', ab, a + b, r+

Explanation
  1. 'rb' — This mode opens the file for reading in binary mode. It will not erase the existing data and allows reading of the file.
  2. 'ab' — This mode opens the file for appending in binary mode. It will not erase the existing data but will append new data to the end of the file.
  3. 'a + b' — This mode opens the file for reading and appending. It will not erase the existing data and allows both reading from and appending to the file.
  4. 'r+' — This mode opens the file for reading and writing. It will not erase the existing data and allows both reading from and writing to the file.