

(): returns a java.io.File object representing the root directory of the internal storage for your application from the current context.Here are some of the methods used to get the paths to the internal storage: Also, Android 4.4 introduces the concept of multiple users: in that case, the internal and external storage depend on the user logged in and the files of the other users will be invisible. You should never hardcode the path to the storage directories, since the directory may changes depending on the version of the Android OS used. On some older or cheaper devices, the internal storage is quite limited, so you need to be careful about the size of the data you save if you need to support those devices. The internal storage is also where your application is installed by default, so your files will always be available. Since the internal storage is private to your application, the files will be deleted if your application is uninstalled. This is the kind of storage to use if the user shouldn’t be able to modify the file from outside your application, and if other application shouldn’t be able to access those files. Internal StorageĮach application has its own private internal storage to save files. Depending on how the user will interact (or not) with your files, you will need to decide first which kind of storage to use. On the other hand, there is less overhead and it easier to work with files than debugging with the data in a database. For complex data, a database may be a better option, since accessing and parsing a large file can be slow and there are no integrity checks unless you code them by hand. There are many situations where you may need to save a file: you may want to use an existing file format to create files that can be opened by the user in another application or the data is simple enough that it can be represented by a text file or a format like XML or YAML.

This post is about saving to a file from an Android application, which is the easiest way to store data. This is the second post in my series about storage in Android applications.
