A file represents a sequence of bytes on the disk where a group of related data is stored. File is created for permanent storage of data. It is a readymade structure. The fopen() function is used to create a new file or to open an existing file.
File Mode | Meaning of Mode | During Inexistence of file |
---|---|---|
r | Open for reading. | If the file does not exist, fopen() returns NULL. |
rb | Open for reading in binary mode. | If the file does not exist, fopen() returns NULL. |
w | Open for writing. | If the file exists, its contents are overwritten. If the file does not exist, it will be created. |
wb | Open for writing in binary mode. | If the file exists, its contents are overwritten. If the file does not exist, it will be created. |
a | Open for append. i.e, Data is added to end of file. | If the file does not exists, it will be created. |
ab | Open for append in binary mode. i.e, Data is added to end of file. | If the file does not exists, it will be created. |
r+ | Open for both reading and writing. | If the file does not exist, fopen() returns NULL. |
rb+ | Open for both reading and writing in binary mode. | If the file does not exist, fopen() returns NULL. |
w+ | Open for both reading and writing. | If the file exists, its contents are overwritten. If the file does not exist, it will be created. |
wb+ | Open for both reading and writing in binary mode. | If the file exists, its contents are overwritten. If the file does not exist, it will be created. |
a+ | Open for both reading and appending. | If the file does not exists, it will be created. |
ab+ | Open for both reading and appending in binary mode. | If the file does not exists, it will be created. |
Types of Files
When dealing with files, there are two types of files you should know about:
Text files
Binary files
1. Text files
Text files are the normal .txt files that you can easily create using Notepad or any simple text editors.
When you open those files, you'll see all the contents within the file as plain text. You can easily edit or delete the contents.
They take minimum effort to maintain, are easily readable, and provide least security and takes bigger storage space.
2. Binary files
Binary files are mostly the .bin files in your computer.
Instead of storing data in plain text, they store it in the binary form (0's and 1's).
They can hold higher amount of data, are not readable easily and provides a better security than text files.
No comments:
Post a Comment