FILE FORMATS
File
formats can be categorized into two ways as: Text mode format and Binary
mode format. This classification
arises at the time of opening the file.
When
a file is opened either in “r”, “w” or “a” modes, default file format is text mode format. If the user wants to open the file in
binary format, explicitly necessary to specify as “rb”, “wb”, or “ab”.
There
are three main differences raised between a text file and binary files. Those are:
1.
Handling
of new lines
2.
Representation
of End-Of-File
3.
Storage
of numbers.
1. In
text mode, a new line character is converted into the combination of carriage
return – line feed before being written into the disk.
In
binary mode, conversions not take place.
A new line character is written into the disk as in the original format.
2. In
text mode, a special character is inserted after the last character in the file
to mark the End-Of-File. If this
character is detected at any point in the file, then read function would return
the EOF signal to the program.
In
binary format, there is no such special character present to mark the
End-Of-File. The binary mode files keep
track of the End-Of-File from the number of characters present in the directory
entry of the file.
3. In
text mode, while storing numbers in files, numbers are stored as string of
characters.
Consider
a number 4523.
In memory, it occupies 2 bytes. Whereas when the number placed on the disk,
it would occupy 4 bytes as one byte per each character. Since, it depends on magnitude of the number.
In such case, large amount of data storage in a
disk file is inefficient.
No comments:
Post a Comment