Alain Cruz
Alain Cruz

Reputation: 5097

Writing to text file created manually inside app

Is it possible in Android, to manually add a file inside a project and then, modify it? Example:

"I have a test.txt file in the following path: "app/src/data". I would like to make a method to write a given String in the test.txt file."

Is that possible? I been looking everywhere, but can't seen to do such an easy task.

Upvotes: 0

Views: 50

Answers (1)

rupps
rupps

Reputation: 9907

If you mean modifying files inside the APK itself then it's not possible. Besides, the folder structure you see in the project is not the final structure on the APK (just unzip your APK, it's a .ZIP really): Fpr example, the source directory is all compiled into a classes.dex. The res/ directory is compiled and fully copied ...

Take a look at How to write files to assets folder or raw folder in android?

and https://developer.android.com/training/basics/data-storage/files.html

You can read raw files stored in /res/raw, or assets stored in assets/ , but you cannot modify stuff inside the APK itself.

What you can do is create and modify as many files as you wish from the different places Android gives to any app, such as:

  • CACHE directory (context.getCacheDir() -> /sdcard/Android/data/your.package/cache

  • External files (context.getExternalFilesDir() -> /sdcard/Android/data/your.package/files

  • Arbitrary directories in the SDCARD.

Upvotes: 2

Related Questions