Android File System
Android File System
The Android file system is a structured environment built on top of the Linux kernel that manages and organizes data storage across the device. It provides isolated storage spaces for each application, shared directories for user content, and protected partitions for the operating system itself. By the end of this lesson, you will be able to:
- Identify the major partitions and directories in the Android file system.
- Explain the difference between internal storage and external storage.
- Describe how scoped storage restricts direct access to shared files.
- Apply the correct storage API for a given use case.
Partitions and Directory Structure
Android organizes the file system into several key partitions, each serving a distinct role:
- System Partition (
/system): Contains the operating system, framework libraries, system apps, and configuration files. This partition is mounted as read only to prevent unauthorized modifications. - Data Partition (
/data): Stores all application data. Each app has a private directory at/data/data/<package_name>that only that app can access, enforced by Linux file permissions tied to the app's UID. - Cache Partition (
/cache): Holds temporary data such as OTA update files. Contents do not persist across factory resets. - Vendor Partition (
/vendor): Contains hardware specific libraries, firmware, and configuration files provided by the device manufacturer. Like/system, this is read only. - External Storage (
/sdcardor/storage): Provides shared storage accessible to multiple apps. Despite the name, this is typically internal flash memory rather than a removable SD card on modern devices.
On devices with multiple user profiles, each user has a separate /data/user/<userId> directory. The Context methods automatically resolve to the correct user directory, so apps do not need to handle multi user paths manually.
Internal Storage
Internal storage refers to the private directory assigned to each application under /data/data/<package_name>. Files written here are accessible only by the owning application. The Android framework provides Context methods to work with this space:
// Write a file to internal storage
val file = File(context.filesDir, "config.json")
file.writeText("""{"theme": "dark"}""")
// Read it back
val content = file.readText()
Files in filesDir persist until the app is uninstalled or the user clears app data. For temporary files, use cacheDir, which the system may delete when storage runs low. The noBackupFilesDir directory provides a location for files that should persist locally but should not be included in Auto Backup, such as device specific tokens or registration IDs.
Internal storage is always available because it resides on the device's built in flash memory. It does not require any runtime permissions, and the data is automatically removed when the user uninstalls the app or clears its data through Settings.
Use context.openFileOutput() and context.openFileInput() for simple read and write operations on internal storage. For structured data, Room or DataStore are preferred because they handle concurrency, migrations, and reactive updates out of the box. SharedPreferences is appropriate for small key value pairs but has known issues with synchronous disk I/O on the main thread and lack of transactional guarantees, which DataStore addresses.
This interview continues for subscribers
Subscribe to Dove Letter for full access to exclusive interviews about Android and Kotlin development.
Become a Sponsor