Reputation: 39
I'm new to Stack Overflow, but I have a question about writing some Java code for an Android program.
I'm building a game for the Android phone, and when we are building levels we are aiming to scan them from text files that are stored in the res/raw for our project. My problem is that I can't figure out how to decode the resource in such a way that it can be interpreted by the Scanner. Right now my line of code just looks like:
Scanner input = new Scanner(new File((R.raw.level1));
This is pretty much just a reinterpretation of the equivalent Java code, which would take a string with the level name. I'm guessing that I'm supposed to be using something like decodeResource for BitmapFactory, but I'm not sure where to look! Perhaps I shouldn't be approaching it as a File at all?
Thank you in advance for your help!
Upvotes: 0
Views: 312
Reputation: 9886
In your Activity:
Scanner input = new Scanner(MyActivity.this.getResources().openRawResource(R.raw.level1));
Upvotes: 2