01What exactly is a file?
We use files every day: a photo, a Word document, a song, or a program can all be saved on a computer as files.
More precisely, a file is a group of related data managed by a file system. The operating system gives it a name and records where its data is stored.
Photo file
Stores image data
Document file
Stores text, layout, and other data
Audio file
Stores encoded sound data
02Are a file name and its contents the same thing?
No. The file name helps people and programs find it. The contents are the data that is actually stored.
Helps us identify the file
FF D8 FF E0 ...The bytes that are actually stored
You can rename a file, but changing its name does not automatically change its data.
03Where does a file “live”?
Files are usually stored on an SSD, hard drive, USB drive, or memory card. But one file does not necessarily occupy one continuous block of space.
A file system divides a storage device into manageable areas and records which areas hold each file’s data.
One file
It looks like one complete object to us
Storage areas underneath
File data may be spread across different locations
04What does a file system do?
If a storage device were only a collection of bytes, the computer would still need rules to manage which data belongs to each file, what each file is called, which folder it is in, and how much space it uses.
Those organizing rules make up a file system.
Record names
What the file is called
Record locations
Which folder contains the file
Record storage areas
Which spaces hold the data
Record properties
Information such as times and permissions
Common file systems include NTFS, APFS, ext4, and exFAT. They work differently inside, but all solve the problem of organizing and managing files.
05What does file size mean?
File size usually tells you how many bytes of content the file has.
A tiny text file
About a few thousand bytes
A compressed photo
About a few million bytes
A large video file
About a few billion bytes
But note that file size and the actual space it occupies on disk may not be exactly the same.
06Why are there different file formats?
Different kinds of information need different ways to be organized and encoded.
JPEG / PNG
Organize image data
MP3 / FLAC
Organize audio data
MP4
Often package video, audio, and other data
TXT / JSON
Store text or structured text data
When a program opens a file, it must interpret the bytes according to the rules of the corresponding format.
07What happens when you open and save a file?
When you double-click a file, the operating system finds it and gives it to a suitable program to read.
Find the file
The file system locates it from its path
Read the data
Load the needed data into memory
Program interprets it
Parse the file contents according to the format
Saving works roughly in reverse: the program encodes the current contents in a file format, then asks the operating system to write the data back to storage.
08How are files and folders different?
Files mainly store content. A folder (or directory) mainly organizes files and other directories.
File
Stores specific data
For example, a photo, document, or programFolder / directory
Organizes names and hierarchy
Can contain files and subdirectoriesWhat have you learned?
- A file is related data managed by a file system, not just an icon on the desktop.
- A file name and its contents are different; renaming usually does not change the data inside.
- A file’s data may be spread across different areas of storage rather than stored continuously.
- The file system manages names, folders, storage locations, sizes, times, permissions, and other details.
- File size usually describes the number of content bytes, but may differ from the disk space used.
- A file format specifies how data is organized, and software must interpret it using the right format.
- When a file is opened, the system reads it into memory for the program to parse; when saved, changes are written back to storage.
- Files mainly store content, while folders / directories organize files and their hierarchy.
Next question: If a file name and its contents are different, what are extensions such as .jpg, .txt, and .cpp for? Next: Why Do Files Have Different Extensions?