Android uses a file system that's similar to disk-based file systems on other
platforms. This page describes how to work with the Android file system to read
and write files with the
File object works well for reading or writing large amounts of data in
start-to-finish order without skipping around. For example, it's good for image
files or anything exchanged over a network.
The exact location of the where your files can be saved might vary across devices, so you should use the methods described on this page to access internal and external storage paths instead of using absolute file paths.
Choose internal or external storage
All Android devices have two file storage areas: internal storage and external storage. These names come from the early days of Android, when most devices offered built-in non-volatile memory (internal storage), plus a removable storage medium such as a micro SD card (external storage). Many devices now divide the permanent storage space into separate "internal" and "external" partitions. So even without a removable storage medium, these two storage spaces always exist, and the API behavior is the same regardless of whether the external storage is removable.
Because the external storage might be removable, there are some differences between these two options as follows.
- It's always available.
- Files saved here are accessible by only your app.
- When the user uninstalls your app, the system removes all your app's files from internal storage.
Internal storage is best when you want to be sure that neither the user nor other apps can access your files.
- It's not always available, because the user can mount the external storage as USB storage and in some cases remove it from the device.
- It's world-readable, so files saved here may be read outside of your control.
- When the user uninstalls your app, the system removes your app's files from
here only if you save them in the directory from
External storage is the best place for files that don't require access restrictions and for files that you want to share with other apps or allow the user to access with a computer.
Note: Although apps are installed onto the internal storage by
default, you can allow your app to be installed on external storage by
attribute in your manifest. Users appreciate this option when the APK size is
very large and they have an external storage space that's larger than the
internal storage. For more information, see App Install Location.
For more information about saving files to the device's storage, consult the following resources.