When the word “file” is referred, it implies either one of the two meanings:
A physical file:
A file is stored on a storage device such as hard disk in several scattered pieces.
A logical file:
A data file is a collection of information stored together.
It is the file type processed and viewed by the application programs.
Before the program can open a file for use, the operating system must receive instructions about making a hookup between a logical file and some physical file or device.
A Program Example
The program below shows how to create and write to a file:
Creates a text file named test.txt located in the local directory, where the program is stored.
The text “This is only a test.” is written on it by using the insertion operator <<.
List the contents of the file test.txt by using the Unix command cat.
Display the text “The file test.txt is created.” on the standard output.