Where are Termux files stored

Michael Jentsch

Every Android app developer is faced with the task of storing data at some point, and Android offers a number of options here, which have advantages and disadvantages. Here are the top 3 ways to save data in an app.

  • SQLite database
  • SharedPreferences
  • Files in the file system

If you decide to work with files in the file system, the question arises directly, how can I access the file system and what restrictions are there here?

The file system is accessed using the Java.io classes, as is known from classic Java development. There is the FileInputStream, the FileOutputStream, the File class and much more.
Here is a small example: (Untested)

String defaultDataDir = "/ data / data /" + getPackageName (); String filename = defaultDataDir + "/text.txt"; FileOutputStream out = new FileOutputStream (filename); byte [] buffer = (“This is a test“). getBytes (); out.write (buffer); out.flush (); out.close ();

In this example the file is created in the so-called “Default Data Directory”. This is a special directory that only this application can access. If it is necessary to store the data elsewhere, this is also possible. However, you must then assign the WRITE_EXTERNAL_STORAGE authorization to the app. This is done via an entry in the Android manifest.


If the app has the WRITE_EXTERNAL_STORAGE authorization, that does not mean that it is possible to have unlimited access to the storage. Both read and write access is only possible in the "/ sdcard /" directory. For everything else you need a rooted device. But as an app developer, in most cases you cannot assume that the users have a rooted Android device.

Often used directories in the Default Data Directory are:

  • databases /: SQLite databases are mostly created here
  • lib /: Libraries and other tools go here
  • shared_prefs /: The SharedPreferences are saved in this directory
  • files /: Other
  • cache /: The app cache

This structure of the app home directory can be expanded at will. The directory is comparable to a Linux user home directory. The app is the user and has control over the files and directories.

Reading and writing files is very easy. However, the decision about the storage location should not be made hastily. Application files that are shared with other apps should be saved on the sdcard. Sensitive data that should only be accessible from your own app should definitely be saved in the default data directory.
Note: The "Default Data Directory" is also not 100% secure against external access. There are no longer any restrictions on rooted devices. With a rooted Android Habdy / Tablet and the corresponding know-how, you can also access the default data directory of any app. Therefore, this is by no means the right place to store e.g. passwords or credit card data unencrypted.

My apps in the Google Play store

Posted in Android