Breaking

Friday, July 20, 2018

Introduction to File & different Type of File with Operation in File

Introduction to File:

A file is a collection of related records that are permanently stored in secondary storage. A file can contain a combination of characters, words or records. 

A file is a collection of data stored in one unit, identified by a filename. It can be a document, a picture, audio or video stream, data library, application, or other collection of data.


introduction to file in os with types of file and operation on file

Types of File

A file is mainly classified into two types on the basis of data stored on the File:


 Text file: 

The file that stored data in text format is called a text file. A text file is easily readable by a human directly. It contains plain ASCII characters (A-Z, 0-9 and special symbols). A computer does not directly understand such text files. Text File takes a lot of space for storage. 

 Binary file:

The file that stored data in binary format (in form of 1’s /0’s) is called a binary fileA binary file consists of binary data (1’s and 0’s).
 
A binary file is not readable by humans but readable by computers. Binary files are directly processed by computers. Binary files take less space to store data compared to text files.

The best example of the binary file is the object file of a C++ source file that is generated by the compiler of C++. 

Different types of Operation Performed on File:

There are various types of operation that can be performed on files in C++. These operations are collectively called file handling. Following are some operations that can be performed on files. 


i. Opening a file: 


Before performing any operation on a file the file must be opened. To open a file open() function is used.  Syntax:  myFile.open(file_name); 


ii. Reading a file: 

To read a word from a file is called a reading operation.  The following syntax is used to read a word from the file. Syntax:  myFile>>c; where c is a character array.
  

iii. Closing a file: 

Once we have read a file. It must be closed. We can perform a closing operation on file by using the following statement:  myFile.close(); 

iv. Opening a File in binary mode: 

We can open a file in binary mode. The following statements are used to open a file in binary mode. Ofstream myFile; myFile.open(“file_name”, ios:: binary);  where “file_name” is the name of a file you want to open in binary mode.  

No comments:

Post a Comment