0
12kviews
What is Files? Explain the different modes of File
1 Answer
1
1.7kviews

Files

  • A File is a part or portion of a computer system that stores data, information, settings, or commands, which are used with a computer program.
  • There are several types of files available in the computer system such as Directory files, FIFO files, Special files, Data files, Text files, Binary and Graphic files, and these several kinds of files contain different types of information.
  • In the computer system, files are stored on hard drives, optical drives, discs, or other storage devices.
  • The file can be contained the data from system-generated information to user-specified information.
  • File management is done manually at times with the help of the user or done with the help of third-party tools and operating systems.

File Modes

  • The File Mode determines where the file is positioned when opened, what functions are allowed, not allowed.
  • A file mode can be categorized into four types of modes.
  • After closing a file, it can be reopened in a different mode, depending on what type of work need to be done.
  • A file always can be opened in one of the four modes.
  • The four file modes are as follows:

1] Create Mode

  • Opens the specified file and positions it to the beginning.
  • If a file by that name does not exist, the openfile() statement creates the file.
  • If a file by that name exists, it overwrites the existing file, except in VMS (Here it creates a new version of the file. It does not overwrite the file unless the file version limit is reached).
  • To create a new file, open the file in create mode.
  • User cannot read, position, or rewind a file opened with create mode.

2] Read Mode

  • This mode opens a file for the reading of data.
  • Read mode opens a file to the beginning.
  • User cannot write to a file opened in the read mode.
  • User can reposition a binary or stream file in this read mode.

3] Update Mode

  • This mode allows both reading and writing of data.
  • Update mode opens a file to the beginning.
  • User can update a record by repositioning the file to the beginning of the record, then writing the new data.
  • User can reposition a binary or stream file in update mode.

4] Append Mode

  • This mode allows writing data to the end of a file.
  • User cannot read, position, or rewind a file opened with append mode.
  • For example, a user can create a file in create mode. Then the user can close the file and later reopen it in append mode to add more data.
Please log in to add an answer.