App internal storage is a dedicated space on the device accessible only to a specific application through isolated storage. According to Android Developers, 2026, each application receives its own sandbox directory that other applications cannot directly access. This approach protects data from unauthorized reading and ensures stable operation in a multitasking mobile environment.
Key Takeaways
Context.getFilesDir(), getCacheDir() and getDataDir() for accessing internal storageNSDocumentDirectory and NSCachesDirectory in the app Sandbox containerApp internal storage is an isolated directory that the operating system allocates to each application during installation. Other applications and the user cannot access this directory through standard file managers. The system guarantees that all data within this directory will be completely deleted when the application is uninstalled. This approach forms the foundation of the mobile operating system security model, preventing confidential information leakage between programs.
Unlike external storage (SD card), internal storage is always available and does not require checking for media presence. Read and write speeds to NAND flash memory in modern devices reach 800–900 MB/s sequential read and 200–300 MB/s sequential write, comparable to SATA SSDs. The allocated area size depends on the total device capacity and manufacturer policy: on devices with 64 GB of flash memory, an app receives 16 to 64 MB of initial space with the ability to expand as needed.
The internal storage architecture differs between Android and iOS. On Android, each application receives a /data/data/<package_name>/ directory, inside which the system creates files/, cache/ and databases/ subdirectories. On iOS, the application runs in a Sandbox container with Documents/, Library/ and tmp/ directories, each with its own purpose and backup policy.
Developers have access to several methods for saving data in app internal storage. Each method solves a specific task and suits a particular type of data. Choosing the right approach directly affects application performance, development convenience, and user data security.
The lowest-level approach is direct file writing to the files directory. An app can create any files and directories inside its sandbox. This method is suitable for storing media files, user documents, and any binary data that does not require structured organization. On Android, directory access is done through the Context.getFilesDir() call, which returns the absolute path to the app’s files directory. On iOS, the NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) function serves a similar purpose.
For storing key-value pairs, Android offers SharedPreferences and the more modern DataStore based on Kotlin coroutines and the protobuf protocol. SharedPreferences stores data in an XML file inside the /data/data/<package>/shared_prefs/ directory. Despite its simplicity, SharedPreferences has drawbacks: synchronous writes can cause delays on the UI thread, and the lack of type safety increases the risk of errors. DataStore solves these problems by providing an asynchronous API based on Flow and full type support through protobuf schemas.
For structured data with relational connections, SQLite or the Room wrapper is the optimal choice. The database is stored in a single file inside the databases/ directory and supports full SQL syntax. Room is an official Jetpack library that provides a type-safe API, automatic schema migration, and coroutine support. The database size can reach several gigabytes without significant performance loss with proper indexing. SQLite on mobile devices handles up to 50,000 write operations per second on a modern flagship processor.
For storing confidential data such as authentication tokens and encryption keys, Android provides EncryptedSharedPreferences. This wrapper over standard SharedPreferences automatically encrypts keys and values using AES256-GCM-None. Encryption is performed at the file level before writing to disk, so even with physical access to the device, an attacker cannot read the contents. EncryptedSharedPreferences is part of the AndroidX Security library, which also includes EncryptedFile for encrypting entire files.
The Android SDK provides a set of methods for working with internal storage through the Context class. Each method returns a path to a specific system directory inside the app sandbox. Let us look at basic file write and read operations using Kotlin as an example.
The main method for obtaining the path to the internal file directory is context.filesDir. It returns a File object pointing to the /data/data/<package>/files/ directory. On first access, the system automatically creates all necessary parent directories. File sizes in internal storage are not explicitly limited, but the total data volume must not exceed the available space on the /data partition, which typically ranges from 60–80% of the total flash memory capacity.
val context = getApplicationContext()
val file = File(context.filesDir, "notes.txt")
file.writeText("Note content")
val content = file.readText()
println("Read: $content")
The writeText and readText methods are extension functions from the Kotlin standard library. They automatically manage opening and closing streams, preventing memory leaks. For binary data, use writeBytes and readBytes, which do not require encoding and work with ByteArray arrays. When working with large files, it is recommended to use buffered streams: BufferedReader and BufferedWriter for text, BufferedInputStream and BufferedOutputStream for binary data.
To organize files into a hierarchy, create subdirectories inside filesDir. This helps structure data by type: images, documents, export files. The mkdirs() method creates all missing directories in the path, including nested ones. Make sure the creation operation succeeds — the method returns true only when new directories are created. Creation failures are most often related to insufficient space on the /data partition or file system inode exhaustion.
val imagesDir = File(context.filesDir, "images")
if (imagesDir.mkdirs()) {
println("Directory created")
}
val imageFile = File(imagesDir, "photo.jpg")
imageFile.writeBytes(byteArray)
To check available space before writing large files, use File.getFreeSpace() or File.getUsableSpace(). The second method returns the number of bytes available to the current application considering security quotas — it is more accurate in the context of multi-user devices. If available space is less than the expected file size, show the user a message and suggest freeing up space in the device settings.
On iOS, each application runs in an isolated Sandbox container. The system does not provide an API to go beyond its boundaries without special entitlements. The main tool for working with the file system is the FileManager class from the Foundation framework. The Sandbox container includes several standard directories, each with its own backup policy.
The Documents directory is intended for user data that should persist between application launches and be restored from backup. iOS automatically includes this directory in iCloud and iTunes backups. The urls(for:in:) method returns an array of URLs for the requested directory — the first element in the array is the primary one.
let fm = FileManager.default
let docs = fm.urls(
for: .documentDirectory,
in: .userDomainMask
).first!
let fileURL = docs.appendingPathComponent("data.plist")
try data.write(to: fileURL)
FileManager supports a full set of file operations: creating, copying, moving, deleting and renaming files. Each operation can throw an error, so all calls must be wrapped in a do-catch construct. Pay special attention to file deletion — the operation is irreversible, and restoring data after removeItem(at:) is impossible without a prior backup.
Not all data in the Sandbox container should be included in iCloud backups. For example, cached downloaded images or temporary processing files do not need to be restored — they will be recreated on next use. To exclude a directory or file from backup, set the isExcludedFromBackup attribute to true. Apple recommends always excluding from backup data that can be restored remotely, to minimize iCloud storage usage and reduce recovery time.
var cacheURL = fm.urls(
for: .cachesDirectory,
in: .userDomainMask
).first!
cacheURL.hasExcludedFromBackupKey = true
var values = URLResourceValues()
values.isExcludedFromBackup = true
try cacheURL.setResourceValues(values)
Each storage type on a mobile device has its own purpose and usage rules. Understanding these differences helps developers choose the right place for each type of data. Below is a comparison of the three main storage types available to an application.
| Characteristic | Internal Storage | Cache Directory | External Storage |
|---|---|---|---|
| Visibility to other apps | Hidden | Hidden | Accessible |
| Deletion on app uninstall | Complete | Complete | Depends on location |
| Backup | Android — no, iOS — yes (Documents) | No | Only when syncing |
| Availability without media | Always | Always | Requires SD card |
| Data loss risk | Minimal | High | Medium |
| Recommended file size | Up to 100 MB | Up to 50 MB | Any |
Internal storage is optimal for storing app configurations, database files, and user documents that should not be accessible to other programs. The cache directory is intended for temporary files that can be recreated on next use: downloaded images, API responses, intermediate processing data. External storage is best suited for large media files (photos, videos, music) and data that users want to share with other applications through shared access.
Choosing the storage type also affects the app rating in Google Play and the App Store. Applications that store large amounts of data in internal storage without cleanup receive negative reviews: users complain about insufficient space. According to an App Annie study, 62% of users delete an app if it takes up more than 500 MB of internal device storage without a cleanup option.
Proper management of app internal storage improves performance, security, and user experience. The following recommendations are based on official Android and iOS documentation, as well as practical experience developing applications with millions of installs.
Special attention should be paid to testing edge cases. Check application behavior when internal storage is full, when a write operation is interrupted unexpectedly (app crash, incoming call), and when restoring from an iOS backup. In each of these scenarios, data must remain consistent or be restored to the last stable state. Use transactional files: write data to a temporary file, then atomically rename it to the target. This prevents reading corrupted data on write failure.
Do not forget about user control. Provide an option in the app settings to clear temporary data and display the used internal storage volume. According to Google Play Console, apps with this feature receive 18% more positive reviews in the “Performance” category.
Frequently Asked Questions
All data from the app’s internal storage is completely deleted. The operating system guarantees the absence of residual files, including databases, settings, and temporary files. Data on external storage may persist.
Without root access to the device, other apps cannot read files from another app’s Internal Storage. On Android, this requires superuser privileges, while on iOS, isolation is enforced at the kernel level through Sandbox.
There is no explicit limit, but the total volume is constrained by the available space on the /data partition. It is recommended not to exceed 100 MB per application — larger volumes are better placed on external storage or in the cloud.
filesDir is intended for permanent app data and is not deleted by the system unless necessary. cacheDir is for temporary files that the system may delete when memory is low. The system does not guarantee cacheDir persistence.
Direct copying from Internal Storage to an SD card is prohibited by security policy. Use the MediaStore API on Android 10+ or SAF (Storage Access Framework) to create copies of data in shared storage with user consent.
Summary
We will develop a mobile application turnkey
IT Sectr creates iOS and Android applications for startups and businesses since 2017. We will advise you and propose the best solution.
Read also