-2

I want to have a JSON file where i can read and write data in my app. And i want to create the file during development. Not during the app download on the phone storage. Since all file under /res are read-only where can i put my JSON file ? Certainly in the internal storage of my app but is it accessible from Android Studio?

Thanks for your time.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Tom
  • 133
  • 2
  • 11
  • 1
    Use your app's internal storage – PPartisan Dec 11 '19 at 16:08
  • How can i drop a file in it from android studio ? I don't think this i feasible, there is no folder in android studio that is a read/write folder ? – Tom Dec 11 '19 at 16:11
  • You don't do it via the graphical interface - you create a file programmatically and write/read from it. [Here's an example](https://stackoverflow.com/a/44587950/1219389) – PPartisan Dec 11 '19 at 16:22
  • Yes but the idea was to store some data directly during development and update them when user use the app. – Tom Dec 11 '19 at 16:23

2 Answers2

1

You can't embed a file with read/write permission in your APK.

I suggest you to embed a read-only file, in asset or raw folders for example, and at the first launch, you copy it into the internal storage to have a read/write version of the file.

Bruno
  • 3,872
  • 4
  • 20
  • 37
-1

You can store your file in the res/raw folder, right click res and add a new Resource Directory

enter image description here

Name your folder raw

Then, you can access your file like so:

InputStream ins = getResources().openRawResource(
            getResources().getIdentifier("filename_without_ext",
            "raw", getPackageName()));
gkpln3
  • 1,317
  • 10
  • 24