What Is File in Data Structure With Example?


Angela Bailey

A file is an essential concept in data structure that allows us to store and organize data in a structured manner. In this article, we will explore what exactly a file is and how it can be used with the help of various examples.

What is a File?
In the context of computer science, a file refers to a collection of related information that is stored on a storage medium such as a hard disk or solid-state drive (SSD). It can be seen as a container for data, which can be accessed and manipulated by programs or users.

Types of Files
There are different types of files that serve various purposes. Some common types include:

  • Text Files: These files store textual data, such as plain text documents or source code files. They can be opened and edited using text editors like Notepad or Sublime Text.
  • Binary Files: Binary files store data in binary format, which means that they contain non-textual information.

    Examples include image files (JPEG, PNG), audio files (MP3), video files (AVI), etc.

  • Executable Files: These files contain instructions that are executed by the computer’s operating system. They typically have extensions like .exe (Windows) or .app (Mac).

The Structure of a File
A file consists of two main components: metadata and actual data.


The metadata provides information about the file itself. It includes details such as the file name, size, type, creation date, and permissions. This information helps the operating system manage and manipulate the file efficiently.


The actual data contained within the file depends on its type. For text files, it may consist of characters, words, or lines of text.

Binary files, on the other hand, store data in a non-textual format. For example, an image file stores pixel values and color information.

Let’s consider an example to understand the concept of a file better. Suppose we have a text file named “example.txt” that contains the following lines:

Hello, World! This is an example file. 

It demonstrates the usage of files in data structures. 

In this example, “example.txt” is the file name. The metadata associated with this file would include details like its size and creation date. The data contained within the file consists of three lines of text.


In summary, a file is a fundamental concept in data structure that allows us to organize and store data. It consists of metadata that provides information about the file itself and actual data that represents the content stored within it. Understanding files is crucial in computer science as they form the backbone for storing and retrieving information efficiently.

Now that you have a better understanding of what a file is and how it works, you can start exploring further topics related to files and data structures. Happy learning!

Discord Server - Web Server - Private Server - DNS Server - Object-Oriented Programming - Scripting - Data Types - Data Structures

Privacy Policy