0

I want to have multiple paths be selected dynamicall in my app, and I was wondering if there is any way you can use a String to identify a file path into the res folder. For example, if I am trying to use an InputStream on a specific text file, I would use this code:

InputStream is = this.getResources().openRawResource(R.raw.textfile);

Is there any way to use a String as a replacement for R.raw.textfile?

Ken White
  • 117,855
  • 13
  • 197
  • 405
Alex N
  • 23
  • 3
  • You can use the `Resources#getIdentifier()` method to get the `int` value to use in place of the `R.raw.textfile`. The linked duplicate is asking about an audio file there, but it's the exact same thing for any `raw` resource. – Mike M. Jul 31 '20 at 20:27
  • Also, the proper tag to use for general Android programming questions is just [android]. The [android-studio] tag is for questions specifically concerning the IDE. – Mike M. Jul 31 '20 at 20:30

0 Answers0