0

My app depends on 3 different files. I already put the two larger ones as expansion files which seems to work fine. Now I don't know where to put the third one (small file). I tried the raw folder but actually I don't know what the path of the file is once it is in those folders.

I tried this here for the raw folder

myClassifier.loadModel( pathToExpansionFiles + "/File1", pathToExpansionFiles + "/File2", R.raw.File3); 

However the return value of R.raw.File3 is an integer, but the function myClassifier expects a string that is the path to File3. Has anyone an idea how to do that?

2
  • Why aren't you using the assets folder, instead of raw folder? Commented Aug 21, 2016 at 19:22
  • I couldn't get it working with the assets folder either so far... Commented Aug 21, 2016 at 19:30

1 Answer 1

1

I tried the raw folder but actually I don't know what the path of the file is once it is in those folders.

There is no path to it. That is a file on your development machine. It is not a file on the device. It is merely an entry inside your APK file.

but the function myClassifier expects a string that is the path to File3

Either switch to some library that works with an InputStream (from getResources().openRawResource()) or make a copy of the data to a local file using that InputStream yourself.

Sign up to request clarification or add additional context in comments.

4 Comments

The last tip sounds promising for my case as the file is an ascii file. Do you have a code snippet for that? If not I can search it up and post the result here. Thanks for your help so far
@mcExchange: I tend to use assets over raw resources, as assets is a bit more flexible (e.g., can have subdirectories). This and this show copying an asset to a file. Just replace the source of the InputStream to use getResources().openRawResource().
Both links are the same. However the code snippet is fine. It does copy the file from assets to some local folder. In my case I chose Environment.getExternalStorage().getAbsolutePath() + "/Android/obb/com.myPackage.name/File3. Unfortunately I cannot reference the file in that folder either. At least android complains about not finding the file. It's weird because I guess the path should be /storage/sdcard0/... but on my test phone the file is under /storage/emulated/legacy/... . But I guess this is another problem / question. Thx so far
@mcExchange: "Both links are the same" -- whoops, sorry, the second one was to highlight lines 57-68. "In my case I chose" -- don't write there. Use an officially supported location (getFilesDir(), getExternalFilesDir(), etc.). "I guess the path should be..." -- probably not. The paths returned by methods will not necessarily map 1:1 to the filesystem, to handle things like multiple user accounts.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.